POV-Ray : Newsgroups : povray.general : Help: Place objects within a circle Server Time
4 Nov 2024 23:17:23 EST (-0500)
  Help: Place objects within a circle (Message 1 to 10 of 20)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Marc Champagne
Subject: Help: Place objects within a circle
Date: 11 Sep 2003 22:11:32
Message: <Xns93F3E154B286BPOVMIKA@204.213.191.226>
Hi folks,

I'm trying (in vain) to write a segment of code that will randomly place
a declared object within a fixed-radious circular x-z plane at a
specific y position. 

Now my math is not so hot, so I thought of placing said objects within a
fixed-size x-z square at a specific y position and use CSG to cut out the
circle of objects I want, but that will leave some objects along the
circumference of the circle partially cut. 

Not very elegant...

Hmmm

Well it took writing this message to figure out that I can place the
object randomly on the x radious and then randomly rotate it arround the
y, it will always remain within the circle. 

Am I on the right track here?

They should have had POV in school, it would of given me a reason to
remember my trigonometry. :) 

Much appreciated. 

-- 
Marc Champagne
marcch.AT.videotron.DOT.ca
Montreal, CANADA


Post a reply to this message

From: Bill DeWitt
Subject: Re: Place objects within a circle
Date: 11 Sep 2003 23:00:01
Message: <3f6136b1$2@news.povray.org>
/// If you don't mind possible overlaps

#declare Name =
sphere
   { 0, 1
     pigment { rgb < 1.0, 0.0, 0.0 > }
   }
#declare R1 = seed(123);
#declare Radius = 25;
#declare Step = 0.05;
#declare I = 0;
#while (I < 1)
   #declare Placement = rand(R1)*Radius;
   object { Name translate < sin(I*(2*pi))*Placement, 0.0,
cos(I*(2*pi))*Placement >  }
   #declare I = I +Step;
#end


Post a reply to this message

From: Slime
Subject: Re: Place objects within a circle
Date: 11 Sep 2003 23:10:21
Message: <3f61391d$1@news.povray.org>
> Well it took writing this message to figure out that I can place the
> object randomly on the x radious and then randomly rotate it arround the
> y, it will always remain within the circle.
>
> Am I on the right track here?


Yes. However, if you do that, you'll find that there's one problem with it:
the objects will be more dense at the center of the circle than at the edge.
This is because each X-coordinate has an equal likelihood of being chosen,
but the ones closer to zero get put in a smaller area (a small circle) than
those closer to the radius of the circle.

To counteract this, you need to "pull" the objects closer to the outer edge
of the circle. The correct way to do this involves calculus (I think), but
I'm pretty sure that it will turn out that you want to take the square root
of the X-value you get.

So:

x = random value from 0 to 1
x = sqrt(x)
x = x * radius of circle
final position = x coordinate rotated randomly around origin

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Warp
Subject: Re: Place objects within a circle
Date: 12 Sep 2003 05:17:32
Message: <3f618f2c@news.povray.org>
Slime <fak### [at] emailaddress> wrote:
> To counteract this, you need to "pull" the objects closer to the outer edge
> of the circle. The correct way to do this involves calculus (I think), but
> I'm pretty sure that it will turn out that you want to take the square root
> of the X-value you get.

  This is a very good guess.
  The scene below demonstrates that sqrt indeed works very well as a
correcting function.
  The first circle (at the left of the image) uses this method to place
the spheres randomly onto it.
  The second circle (at the right) is for comparison: It uses a bit slower
method to truely distribute spheres randomly onto the circle.
  The difference in distribution evenness is practically none.


camera { location -z*6 look_at 0 angle 35 }
light_source { -z*10, 1 }
#default { pigment { rgb 1 } }

#declare Amount = 1000;
#declare CircleRadius = 1;
#declare SphereRadius = .02;

union
{ #declare S = seed(0);
  #declare Ind = 0;
  #while(Ind < Amount)
    sphere
    { vrotate(x*CircleRadius*sqrt(rand(S)), z*360*rand(S)), SphereRadius
    }
    #declare Ind = Ind+1;
  #end
  disc { 0,-z,CircleRadius pigment { rgb z*.5 } }
  translate -x*CircleRadius
}

union
{ #declare S = seed(0);
  #declare Ind = 0;
  #while(Ind < Amount)
    #declare Loc = <rand(S),rand(S),.5>*2-1;
    #while(vlength(Loc) > 1)
      #declare Loc = <rand(S),rand(S),.5>*2-1;
    #end
    sphere { Loc*CircleRadius, SphereRadius }
    #declare Ind = Ind+1;
  #end
  disc { 0,-z,CircleRadius pigment { rgb z*.5 } }
  translate x*CircleRadius
}


-- 
#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: Marc Champagne
Subject: Re: Place objects within a circle
Date: 12 Sep 2003 18:12:51
Message: <Xns93F4B8DE84F66POVMIKA@204.213.191.226>
"Slime" <fak### [at] emailaddress> wrote in news:3f61391d$1@news.povray.org:

>> Well it took writing this message to figure out that I can place the
>> object randomly on the x radious and then randomly rotate it arround
>> the y, it will always remain within the circle.
>>
>> Am I on the right track here?
> 
> 
> Yes. However, if you do that, you'll find that there's one problem with
> it: the objects will be more dense at the center of the circle than at
> the edge. This is because each X-coordinate has an equal likelihood of
> being chosen, but the ones closer to zero get put in a smaller area (a
> small circle) than those closer to the radius of the circle.
> 
> To counteract this, you need to "pull" the objects closer to the outer
> edge of the circle. The correct way to do this involves calculus (I
> think), but I'm pretty sure that it will turn out that you want to take
> the square root of the X-value you get.
> 
> So:
> 
> x = random value from 0 to 1
> x = sqrt(x)
> x = x * radius of circle
> final position = x coordinate rotated randomly around origin

I'm trying real hard to figure out how you came about the idea of using
sqrt(), so I'll take my pen and paper and work some examples to understand 
why this should work.

I'll pop it in my code and try.

Thanks Slime

-- 
Marc Champagne
marcch.AT.videotron.DOT.ca
Montreal, CANADA


Post a reply to this message

From: Marc Champagne
Subject: Re: Place objects within a circle
Date: 12 Sep 2003 18:16:42
Message: <Xns93F4B986040E0POVMIKA@204.213.191.226>
Warp <war### [at] tagpovrayorg> wrote in news:3f618f2c@news.povray.org:

> > Slime <fak### [at] emailaddress> wrote:
> > To counteract this, you need to "pull" the objects closer to the outer
> > edge of the circle. The correct way to do this involves calculus (I
> > think), but I'm pretty sure that it will turn out that you want to
> > take the square root of the X-value you get.

> This is a very good guess.
> The scene below demonstrates that sqrt indeed works very well as a
> correcting function.
> The first circle (at the left of the image) uses this method to place
> The spheres randomly onto it.
> The second circle (at the right) is for comparison: It uses a bit
> slower method to truely distribute spheres randomly onto the circle.
> The difference in distribution evenness is practically none.

I see you tried already, I will study your method to understand how you
came about it. 

Thanks Warp

-- 
Marc Champagne
marcch.AT.videotron.DOT.ca
Montreal, CANADA


Post a reply to this message

From: Marc Champagne
Subject: Re: Place objects within a circle
Date: 12 Sep 2003 18:17:20
Message: <Xns93F4B9A185951POVMIKA@204.213.191.226>
"Bill DeWitt" <bdw### [at] cflrrcom> wrote in news:3f6136b1$2@news.povray.org:

> /// If you don't mind possible overlaps
> 
> #declare Name =
> sphere
>    { 0, 1
>      pigment { rgb < 1.0, 0.0, 0.0 > }
>    }
> #declare R1 = seed(123);
> #declare Radius = 25;
> #declare Step = 0.05;
> #declare I = 0;
> #while (I < 1)
>    #declare Placement = rand(R1)*Radius;
>    object { Name translate < sin(I*(2*pi))*Placement, 0.0,
> cos(I*(2*pi))*Placement >  }
>    #declare I = I +Step;
> #end
> 
> 


Well the declared item will be a sphere for blob use, overlaping
should not be a problem.

I'll give your example a try.

Thanks a 1000 scale 1000 !



-- 
Marc Champagne
marcch.AT.videotron.DOT.ca
Montreal, CANADA


Post a reply to this message

From: Slime
Subject: Re: Place objects within a circle
Date: 12 Sep 2003 18:54:43
Message: <3f624eb3$1@news.povray.org>
> I'm trying real hard to figure out how you came about the idea of using
> sqrt(), so I'll take my pen and paper and work some examples to understand
> why this should work.

I remember why now. The circumference of the circle which passes through a
point x on the X-axis is, of course, 2*pi*x^2 (two pi r squared). Since,
according to this function, the radii of the circles grows at a squared rate
as x gets bigger, you need to take the square root of x to get even
randomness. This spreads out the random points in the correct manner.

Before you try to understand that, though, make sure you understand what the
problem is in the first place with *not* taking the square root.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Marc Champagne
Subject: Re: Place objects within a circle
Date: 12 Sep 2003 19:23:57
Message: <Xns93F4C4ED0C87CPOVMIKA@204.213.191.226>
"Slime" <fak### [at] emailaddress> wrote in news:3f624eb3$1@news.povray.org:

>> I'm trying real hard to figure out how you came about the idea of using
>> sqrt(), so I'll take my pen and paper and work some examples to
>> understand why this should work.
> 
> I remember why now. The circumference of the circle which passes through
> a point x on the X-axis is, of course, 2*pi*x^2 (two pi r squared).
> Since, according to this function, the radii of the circles grows at a
> squared rate as x gets bigger, you need to take the square root of x to
> get even randomness. This spreads out the random points in the correct
> manner. 

Put that way it's easier to understand, I will still prove it to myself (
hehe they use to do just that in math class: you always had to prove your
answers ) 
 
> Before you try to understand that, though, make sure you understand what
> the problem is in the first place with *not* taking the square root.

This part is easy to understand.

Thanks again

-- 
Marc Champagne
marcch.AT.videotron.DOT.ca
Montreal, CANADA


Post a reply to this message

From: Kurts
Subject: Re: Help: Place objects within a circle
Date: 13 Sep 2003 11:58:00
Message: <kurtzlepirate-7C5E24.17575913092003@netplex.aussie.org>
In article <Xns### [at] 204213191226>,
 Marc Champagne <marcch.AT.videotron.DOT.ca> wrote:

> Hi folks,
> 
> I'm trying (in vain) to write a segment of code that will randomly place
> a declared object within a fixed-radious circular x-z plane at a
> specific y position. 
> 
> Now my math is not so hot, so I thought of placing said objects within a
> fixed-size x-z square at a specific y position and use CSG to cut out the
> circle of objects I want, but that will leave some objects along the
> circumference of the circle partially cut. 
> 
> Not very elegant...
> 
> Hmmm
> 
> Well it took writing this message to figure out that I can place the
> object randomly on the x radious and then randomly rotate it arround the
> y, it will always remain within the circle. 

  waht about that :

  #declare alea = seed(a_number);
  #declare rotAngle = 360*rand(alea);

  #declare objet = sphere {
    <xVal, 0, 0>
    radius
    rotate rotAngle*y
    }


> Am I on the right track here?

  yes you are



> They should have had POV in school, it would of given me a reason to
> remember my trigonometry. :) 

  no trigo need for the moment.


> Much appreciated.


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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