POV-Ray : Newsgroups : povray.general : Help with a spherical container Server Time
4 Aug 2024 02:17:26 EDT (-0400)
  Help with a spherical container (Message 21 to 29 of 29)  
<<< Previous 10 Messages Goto Initial 10 Messages
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

<<< Previous 10 Messages Goto Initial 10 Messages

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