POV-Ray : Newsgroups : povray.general : Help with a spherical container Server Time
13 Oct 2026 22:23:47 EDT (-0400)
  Help with a spherical container (Message 1 to 29 of 29)  
From: Wesley Parker
Subject: Help with a spherical container
Date: 4 Nov 2003 19:38:38
Message: <3fa8468e@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.


Post a reply to this message

From: Warp
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 20:22:08
Message: <3fa850c0@news.povray.org>
Wesley Parker <wes### [at] verizonnet> wrote:
> 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.

#declare Seed = seed(0);

#declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
#while(vlength(LightLocation) > 5)
  #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
#end

  After the loop ends you will have a random point inside the sphere
of radius 5 in 'LightLocation'.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Wesley Parker
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 20:33:38
Message: <3fa85372$1@news.povray.org>
Ok, cool. It works great now. Can you explain how that works?

"Warp" <war### [at] tagpovrayorg> wrote in message
news:3fa850c0@news.povray.org...
> Wesley Parker <wes### [at] verizonnet> wrote:
> > 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.
>
> #declare Seed = seed(0);
>
> #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> #while(vlength(LightLocation) > 5)
>   #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> #end
>
>   After the loop ends you will have a random point inside the sphere
> of radius 5 in 'LightLocation'.
>
> -- 
> #macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb
M()}}
> N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
> N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  -
Warp -


Post a reply to this message

From: Christopher James Huff
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 20:40:55
Message: <cjameshuff-618341.20403704112003@netplex.aussie.org>
In article <3fa850c0@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

> #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> #while(vlength(LightLocation) > 5)
>   #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> #end

Or you could just use VRand_In_Sphere() in rand.inc.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 20:44:08
Message: <cjameshuff-E27010.20435004112003@netplex.aussie.org>
In article <3fa85372$1@news.povray.org>,
 "Wesley Parker" <wes### [at] verizonnet> wrote:

> Ok, cool. It works great now. Can you explain how that works?

Find a random point in a 10x10x10 box. If the point is outside the 
radius-5 sphere, find another random point in the box. Repeat until you 
have a random point in the sphere.

The method the include file uses is a bit more complex, but is overall a 
bit faster...the loop method can require several attempts before it 
turns up a useable point.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Warp
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 20:48:55
Message: <3fa85707@news.povray.org>
Christopher James Huff <cja### [at] earthlinknet> wrote:
> The method the include file uses is a bit more complex, but is overall a 
> bit faster...the loop method can require several attempts before it 
> turns up a useable point.

  This is true, but relevant only if you are going to place hundreds or
thousands of points inside the sphere... :)

  Honestly, I didn't remember the macro in the standard include file.
If I had, I would have suggested it.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Wesley Parker
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 21:06:42
Message: <3fa85b32$1@news.povray.org>
this is kinda funny, i changed the amount of lights im going to use from 25
to 250 (and increased the radius to 500) and its been parsing for the last
15 minutes o.O

im just going to go ahead and stop it now and try the function in the
standard include.
"Warp" <war### [at] tagpovrayorg> wrote in message
news:3fa850c0@news.povray.org...
> Wesley Parker <wes### [at] verizonnet> wrote:
> > 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.
>
> #declare Seed = seed(0);
>
> #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> #while(vlength(LightLocation) > 5)
>   #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> #end
>
>   After the loop ends you will have a random point inside the sphere
> of radius 5 in 'LightLocation'.
>
> -- 
> #macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb
M()}}
> N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
> N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  -
Warp -


Post a reply to this message

From: Wesley Parker
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 21:11:20
Message: <3fa85c48$1@news.povray.org>
nah, i cant resist the urge to see how long it takes.

20 minutes and counting...

"Wesley Parker" <wes### [at] verizonnet> wrote in message
news:3fa85b32$1@news.povray.org...
> this is kinda funny, i changed the amount of lights im going to use from
25
> to 250 (and increased the radius to 500) and its been parsing for the last
> 15 minutes o.O
>
> im just going to go ahead and stop it now and try the function in the
> standard include.
> "Warp" <war### [at] tagpovrayorg> wrote in message
> news:3fa850c0@news.povray.org...
> > Wesley Parker <wes### [at] verizonnet> wrote:
> > > 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.
> >
> > #declare Seed = seed(0);
> >
> > #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> > #while(vlength(LightLocation) > 5)
> >   #declare LightLocation = 10*<rand(Seed), rand(Seed), rand(Seed)>-5;
> > #end
> >
> >   After the loop ends you will have a random point inside the sphere
> > of radius 5 in 'LightLocation'.
> >
> > -- 
> > #macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb
> M()}}
> > N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
> > N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  -
> Warp -
>
>


Post a reply to this message

From: Christopher James Huff
Subject: Re: Help with a spherical container
Date: 4 Nov 2003 21:41:41
Message: <cjameshuff-B78040.21412304112003@netplex.aussie.org>
In article <3fa85b32$1@news.povray.org>,
 "Wesley Parker" <wes### [at] verizonnet> wrote:

> this is kinda funny, i changed the amount of lights im going to use from 25
> to 250 (and increased the radius to 500) and its been parsing for the last
> 15 minutes o.O

It shouldn't take *that* long to parse, it may actually be done parsing 
and busy working on light buffers. If it takes too long or runs out of 
memory, try turning off light buffers. Or maybe you made a mistake in 
modifying the code...it will take a very long time to find random points 
in a 5-unit sphere when you use random points from a 1000-unit box.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Kurts
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 01:09:18
Message: <kurtzlepirate-B9FAE6.07091605112003@netplex.aussie.org>
In article <3fa8468e@news.povray.org>, "Wesley Parker" <wes### [at] verizonnet> 
wrote:

> 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.
> 
> 
hi,

you can about that :

take a rayon
take a random number from 0 to 360
take an other random number from +90 to -90
then just convert polar coordonates from this 3 number to rectangular <x,y,z>

pretty simply


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Help with a spherical container
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

From: Warp
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 05:21:29
Message: <3fa8cf29@news.povray.org>
Wesley Parker <wes### [at] verizonnet> wrote:
> this is kinda funny, i changed the amount of lights im going to use from 25
> to 250 (and increased the radius to 500) and its been parsing for the last
> 15 minutes o.O

  With 250 light sources the it will take enormous amounts of parsing
and specially rendering time anyways (but not placing the light sources,
but calculating light buffers).

  If you want to test the speed of the code, place small objects instead,
like tiny spheres.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 05:22:16
Message: <3fa8cf58@news.povray.org>
Kurts <kur### [at] yahoofr> wrote:
> take a rayon
> take a random number from 0 to 360
> take an other random number from +90 to -90
> then just convert polar coordonates from this 3 number to rectangular <x,y,z>

> pretty simply

  You don't get an even distribution that way.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Warp
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 05:24:48
Message: <3fa8cff0@news.povray.org>
Tim Nikias v2.0 <tim.nikias (@) nolights.de> wrote:
> #declare
> Random_Lightsource=vnormalize(<rand(Seed)*2-1,rand(Seed)*2-1,rand(Seed)*2-1>
> )*rand(Seed)*5;

  Are you sure this produces an even distribution?-)

  By the way, you can do: <rand(Seed),rand(Seed),rand(Seed)>*2-1

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 05:47:46
Message: <3fa8d552@news.povray.org>
> > #declare
> >
Random_Lightsource=vnormalize(<rand(Seed)*2-1,rand(Seed)*2-1,rand(Seed)*2-1>
> > )*rand(Seed)*5;
>
>   Are you sure this produces an even distribution?-)

Nah, not sure if this is even distribution. Would be, sorta, if the
rand-function would be TRULY random, but it suffices in most cases anyway.
Randomizing points in a box and then checking if its in the sphere wouldn't
produce even distribution either. So why not save the parsing time of
sorting out unnecessary points?

>   By the way, you can do: <rand(Seed),rand(Seed),rand(Seed)>*2-1

Hm, yeah, right. Can't remember when and how I came to do it this way...

-- 
"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

From: Tom Melly
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 06:29:33
Message: <3fa8df1d@news.povray.org>
"Tim Nikias v2.0" <tim.nikias (@) nolights.de> wrote in message
news:3fa8d552@news.povray.org...

> Nah, not sure if this is even distribution. Would be, sorta, if the
> rand-function would be TRULY random, but it suffices in most cases anyway.
> Randomizing points in a box and then checking if its in the sphere wouldn't
> produce even distribution either. So why not save the parsing time of
> sorting out unnecessary points?

Ignoring the issue of rand-function and TRULY random, I suspect you're missing
the point.

Imagine a disk, now take a random distance along the radius, and then a random
rotation. You will get a disproportionate number of points near the center of
the disk. However, finding truly random points within a square that contains the
disk, and then checking whether they are inside the disk will produce a proper
random distrib. within the confines of the rand method.

You can see this yourself with the following code:

#include "colors.inc"

camera {
  location  <0.0, 0.0, -4.0>
  look_at   <0.0, 0.0,  0.0>
}

disc {
  <0, 0, 0>  // center position
  z,         // normal vector
  1.0,       // outer radius
  0.0        // optional hole radius
  pigment{Red}
  finish{ambient 1}
}

#local Count = 0;
#local MyRand = seed(2534);
#while(Count<1000)
  sphere{
    0,0.025
    translate y*rand(MyRand)
    rotate z*360*rand(MyRand)
    pigment{Green}
    finish{ambient 1}
  }
  #local Count = Count +1;
#end


Post a reply to this message

From: Warp
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 06:53:01
Message: <3fa8e49d@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote:
> Imagine a disk, now take a random distance along the radius, and then a random
> rotation. You will get a disproportionate number of points near the center of
> the disk.

  For the same reason the presented method of normalizing a random point
inside the cube will not give an even distribution of points on the
surface of the sphere. The points will be slightly more concentrated
on the direction of the corners of the box (because there are more points
at those directions than eg. in the direction of the main axes).
  Granted, this concentration difference is very small and probably
mostly unnoticeable, but if mathematical distribution evenness is
important, one should know this limitation.

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 06:53:53
Message: <3fa8e4d1$1@news.povray.org>
> Ignoring the issue of rand-function and TRULY random, I suspect you're
missing
> the point.
>
> Imagine a disk, now take a random distance along the radius, and then a
random
> rotation. You will get a disproportionate number of points near the center
of
> the disk. However, finding truly random points within a square that
contains the
> disk, and then checking whether they are inside the disk will produce a
proper
> random distrib. within the confines of the rand method.

Ah, okay, I get it. You mean with the box approach, the points in the
corners of the box, outside the sphere, will fall out, but in my case,
they'll be introduced into the sphere. Hence a larger distribution of points
in the "axis-corners" of the sphere, right?

Then you're both right about that. Still, depending on the amount of
lightsources required, I'd say there is no need to go into the hassle of the
more difficult approach with if-statements and all that. But that's probably
more an issue of taste, cause with random distribution, it *sometimes*
doesn't matter if its even or not...

-- 
"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

From: Warp
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 08:06:28
Message: <3fa8f5d4@news.povray.org>
Tim Nikias v2.0 <tim.nikias (@) nolights.de> wrote:
> Ah, okay, I get it. You mean with the box approach, the points in the
> corners of the box, outside the sphere, will fall out, but in my case,
> they'll be introduced into the sphere. Hence a larger distribution of points
> in the "axis-corners" of the sphere, right?

  I actually rendered an image to see if the difference in distribution
is visible. I placed 20000 dots on the surface of a sphere using the
normalization method. The distribution is quite visible:

http://www.cs.tut.fi/~warp/images/test.jpg

> Then you're both right about that. Still, depending on the amount of
> lightsources required, I'd say there is no need to go into the hassle of the
> more difficult approach with if-statements and all that.

  It's no hassle to use the VRand_In_Sphere() macro in rand.inc.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Gilles Tran
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 08:08:23
Message: <3fa8f647$1@news.povray.org>
"Wesley Parker" <wes### [at] verizonnet> a écrit dans le message de
news:3fa85c48$1@news.povray.org...
> nah, i cant resist the urge to see how long it takes.
>
> 20 minutes and counting...

Turn off the light buffers: -ul on the command line.

G.

-- 

**********************
http://www.oyonale.com
**********************
- Graphic experiments
- POV-Ray and Poser computer images
- Posters


Post a reply to this message

From: Alain
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 09:07:16
Message: <Xns942A5CCBEE01FCaelum@204.213.191.226>
"Wesley Parker" <wes### [at] verizonnet> wrote in
news:3fa8468e@news.povray.org: 

> [...]
> 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
> [...]

Just another idea for the position.  I think this should distribute quite 
well for your purposes:

(Where 5 is your radius)

5/(1+rand(S))*vnormalize(-1+2*<rand(S),rand(S),rand(S)>)

This was derived from the random distribution:

5*rand(S)*vnormalize(-1+2*<rand(S),rand(S),rand(S)>)

But, given that a sphere will have a higher concentration of points near 
the center, I thought you might prefer to place them inversely 
proportional to the distance from the center.


Post a reply to this message

From: Warp
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 09:21:41
Message: <3fa90775@news.povray.org>
Alain <noe### [at] onca> wrote:
> But, given that a sphere will have a higher concentration of points near 
> the center, I thought you might prefer to place them inversely 
> proportional to the distance from the center.

  I think that the idea was to place random points *evenly* inside the
sphere. Making a higher concentration near the center kind of defies
this goal.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Christopher James Huff
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 09:39:53
Message: <cjameshuff-54E6AE.09393705112003@netplex.aussie.org>
In article <Xns### [at] 204213191226>,
 Alain <noe### [at] onca> wrote:

> (Where 5 is your radius)
> 
> 5/(1+rand(S))*vnormalize(-1+2*<rand(S),rand(S),rand(S)>)

This will not give anything close to an even distribution. The places 
where points in the corners of the box were projected onto the sphere 
surface will have higher densities. And I have no idea what you think 
you're doing by subtracting a uniform random value in the range [0, 1] 
from 1...this has no effect. And then dividing 5 by that value...you do 
know this will give points with distances from the origin from 5 units 
out to infinity, don't you? Points *outside* the sphere, most of them 
*far* outside.


> This was derived from the random distribution:
> 
> 5*rand(S)*vnormalize(-1+2*<rand(S),rand(S),rand(S)>)

Which itself is badly flawed, and won't give anything close to a uniform 
distribution.


> But, given that a sphere will have a higher concentration of points near 
> the center, I thought you might prefer to place them inversely 
> proportional to the distance from the center.

VRand_In_Sphere() gives an even distribution, the density of points is 
equal over the volume of the sphere.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Tom Melly
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 10:22:45
Message: <3fa915c5$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message news:3fa90775@news.povray.org...
> Alain <noe### [at] onca> wrote:
> > But, given that a sphere will have a higher concentration of points near
> > the center, I thought you might prefer to place them inversely
> > proportional to the distance from the center.
>
>   I think that the idea was to place random points *evenly* inside the
> sphere. Making a higher concentration near the center kind of defies
> this goal.
>

Ignoring any possible mis-terms, doesn't Alain's suggestion make sense?

Hmm, testing.... (with my disk-example)...

#include "colors.inc"

#declare MyRadius = .50;
camera {
  location  <0.0, 0.0, -MyRadius*2.5>
  look_at   <0.0, 0.0,  0.0>
}


disc {
  <0, 0, 0>  // center position
  z,         // normal vector
  MyRadius,       // outer radius
  0.0        // optional hole radius
  pigment{Red}
  finish{ambient 1}
}

#local Count = 0;
#local MyRand = seed(457);
#while(Count<10000)
  sphere{
    0,0.01*MyRadius
    translate y*(sqrt(rand(MyRand))*MyRadius)
    rotate z*360*rand(MyRand)
    pigment{Green}
    finish{ambient 1}
  }
  #local Count = Count +1;
#end

Well, that seems to produce a fairly even distribution.... I dunno how you apply
this to 3 dimensions (i.e. a sphere), but it can't be that hard, can it?


Post a reply to this message

From: Alain
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 10:49:07
Message: <Xns942A6E102A455Caelum@204.213.191.226>
Warp <war### [at] tagpovrayorg> wrote in news:3fa90775@news.povray.org:

> Alain <noe### [at] onca> wrote:
>> But, given that a sphere will have a higher concentration of points
>> near the center, I thought you might prefer to place them inversely 
>> proportional to the distance from the center.
> 
>   I think that the idea was to place random points *evenly* inside the
> sphere. Making a higher concentration near the center kind of defies
> this goal.
> 

Yeah, that's not the intention.  I guess this is distributing randomly, but 
radially.  Oh well, it was just an idea.  The first equation will simply 
radially distribute more points towards the outside of the sphere.


Post a reply to this message

From: Alain
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 11:20:26
Message: <Xns942A735F64DB8Caelum@204.213.191.226>
Christopher James Huff <cja### [at] earthlinknet> wrote in
news:cja### [at] netplexaussieorg: 

> In article <Xns### [at] 204213191226>,
>  Alain <noe### [at] onca> wrote:
> 
>> (Where 5 is your radius)
>> 
>> 5/(1+rand(S))*vnormalize(-1+2*<rand(S),rand(S),rand(S)>)
> 
> This will not give anything close to an even distribution. The places 
> where points in the corners of the box were projected onto the sphere 
> surface will have higher densities. And I have no idea what you think 
> you're doing by subtracting a uniform random value in the range [0, 1]
> from 1...this has no effect. And then dividing 5 by that value...you
> do know this will give points with distances from the origin from 5
> units out to infinity, don't you? Points *outside* the sphere, most of
> them *far* outside.

Sorry condescending dude, but I have no idea what you are talking about. 
What subtraction do you have a problem with?  The -1?  It establishes a 
range -1 to +1.  You have a problem with the 1+? It's a simple inversely 
proportional equation.  Besides I just tried it in Pov and it seems to 
work fine.  Yes, it's not an even distribution, it favours points towards 
the outside (but not outside), which was intended in that one.  And, yes, 
even the second equation I gave, as pointed out by Warp, will only 
distribute randomly radially.


Post a reply to this message

From: Christopher James Huff
Subject: Re: Help with a spherical container
Date: 5 Nov 2003 15:31:29
Message: <cjameshuff-DC95CA.15311505112003@netplex.aussie.org>
In article <Xns### [at] 204213191226>,
 Alain <noe### [at] onca> wrote:

> Sorry condescending dude,

What you said was incorrect, so I corrected you. There's no reason to be 
insulting.


> but I have no idea what you are talking about. 
> What subtraction do you have a problem with?  The -1?  It establishes a 
> range -1 to +1.

Bleh, I was misreading 1+rand(S) as 1-rand(S).


>  You have a problem with the 1+? It's a simple inversely 
> proportional equation.  Besides I just tried it in Pov and it seems to 
> work fine.  Yes, it's not an even distribution, it favours points towards 
> the outside (but not outside), which was intended in that one. 

It is more than uneven: 5/(1+rand(S)) will range between 5 and 2.5. The 
interior of the sphere will be empty...you end up filling a hollow shell 
with inner radius 2.5 and outer radius 5. And within this shell, it will 
still be more dense toward the inner side of the shell than the outer 
side.


> And, yes, even the second equation I gave, as pointed out by Warp, 
> will only distribute randomly radially.

This one?
5*rand(S)*vnormalize(-1+2*<rand(S),rand(S),rand(S)>)

That distribution is not even in any way. Points will be more dense 
facing the corners of the cube you pull random points from, so the 
distribution is uneven in angular density. A cone from the center 
pointing at < 1, 1, 1> will contain more points than the same cone 
pointing at < 0, 0, 1>.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From:
Subject: Re: Help with a spherical container
Date: 6 Nov 2003 01:55:14
Message: <3fa9f052@news.povray.org>
Short and slightly faster (by 9%) than VRand_In_Sphere() from rand.inc:

#macro VRand_In_Sphere(Stream)
  #local Y = 2*rand(Stream)-1;
  vrotate ( (<sqrt(1-Y*Y),Y,0>*pow(rand(Stream),1/3)), 360*rand(Stream)*y )
#end


   Sputnik


Post a reply to this message

From: David Wallace
Subject: Re: Help with a spherical container
Date: 17 Nov 2003 16:03:30
Message: <3fb937a2$1@news.povray.org>
If the radius is a simple random number, then the point density varies with
the inverse square of the radius.  This code compensates for the variance:

#macro EvenSpherePoint(pos, rad, sd)
    #local irad = sqrt(min(rand(sd),0);
    #local theta = rand(sd)*2*pi;
    #local phi = (rand(sd)-0.5)*pi;
    #local dir = <cos(phi)*cos(theta), sin(phi), cos(phi)*sin(theta)>;
    #local pnt = pos+dir*irad*rad;
    pnt
#end

To use it--

#declare sdBall = seed(4852); // Sample number
#declare bPos = <0, 0, 0>;
#declare bSiz = 5;

sphere { bPos, bSiz
    pigment { rgbt 1 }
    hollow
    interior { /* your media */ }
}

#local i = 0;
#while (i<45)
    #local col = <rand(sdBall), rand(sdBall), rand(sdBall)>;
    #local pos = EvenSpherePoint(bPos, bSiz, sdBall);
    light_source { pos, rgb col }
    #local i = i + 1; // if using MegaPov v1.0 #set will work
#end

Now you avoid having to check for the sphere's boundary with each point.

"Warp" <war### [at] tagpovrayorg> wrote in message
news:3fa8cf58@news.povray.org...
> Kurts <kur### [at] yahoofr> wrote:
> > take a rayon
> > take a random number from 0 to 360
> > take an other random number from +90 to -90
> > then just convert polar coordonates from this 3 number to rectangular
<x,y,z>
>
> > pretty simply
>
>   You don't get an even distribution that way.
>
> -- 
> #macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb
M()}}
> N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
> N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  -
Warp -


Post a reply to this message

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