POV-Ray : Newsgroups : povray.general : Help with a spherical container : Re: Help with a spherical container Server Time
4 Aug 2024 02:17:26 EDT (-0400)
  Re: Help with a spherical container  
From: Tim Nikias v2 0
Date: 5 Nov 2003 04:20:35
Message: <3fa8c0e3@news.povray.org>
> Hey, i had an idea for something pretty interesting but I am having
problems
> implementing it.  What i did was create a sphere with object media at the
> origin with a radius of five. That part was easy enough, but placing the
> lights is troubling me. I need the placement to be random, but at the same
> time the lights need to be on the inside of the sphere. If they go
outside,
> they light the sphere itself and that destroys the scene. So can anyone
help
> me?
>
> Thanks in advance.

My solution would be as follows:

#declare Seed=seed(1);

#declare
Random_Lightsource=vnormalize(<rand(Seed)*2-1,rand(Seed)*2-1,rand(Seed)*2-1>
)*rand(Seed)*5;

This would generate a random position ON a unit-sphere, but the radius gets
randomized to a value between 0 and 5 (rand(Seed)*5 at the end). If you need
to make sure that the lightsource is a certain distance in the sphere,
reduce the radius, if you want it to range from a certain distance of the
center, multiply with the following:

(rand(Seed)*(Max_Radius-Min_Radius)+Min_Radius)

Don't forget the brackets, cause Value*Value_2+Value_3 is something
different than Value*(Value_2+Value_3)!

This should parse faster than trying to randomly generate a position in a
box and THEN find if its in the sphere, cause it produces a position in the
sphere RIGHT AWAY.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>
Email: tim.nikias (@) nolights.de




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.536 / Virus Database: 331 - Release Date: 03.11.2003


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.