RE: [Algorithms] It's all Random Numbers
Brought to you by:
vexxed72
|
From: Zafar Q. <zaf...@ra...> - 2000-10-31 14:58:51
|
Hi, As Peter-Pike Sloan said, this is discussed in "NonUniform Random Point Sets Via Warping", by Peter Shirley (Graphics Gems III). It's a bit mathematical though. On p.81 is a table showing various transformations. To get a random point on a unit-sphere use:- theta = arccos(1-2u) phi = 2PI * v where u and v are uniformly random between 0.0 and 1.0, theta has domain 0 to PI, phi has domain 0 to 2PI Cheers -Zaf -----Original Message----- From: Ludvig Tunel [mailto:lu...@it...] Sent: 31 October 2000 09:42 To: gda...@li... Subject: Re: [Algorithms] It's all Random Numbers Hi, I came to think of a very similar problem: How do I generate random points in a sphere, ( or on the sphere surface ) using spherical polar coordinates? If i randomize azimuth and inclination I will get denser distribution around the "poles". I would need to transform the randomized[-pi/2 ... pi/2] inclination in some way, but how? Taking the square root doesn't feel like the right thing to do here. It feels more like I should feed it to cos() or sin() in some way... The probability of generating a point at a certain inclination must somehow be transformed to be proportional to the area of the disc at the given inclination. Right? But how? (The problem of denser distribution close to the centre could as I assume from having read the 2D solution, be solved by taking the cube root of the radius. ( radius^(1/3) ) Am I right?) cheers Ludde Gil Gribb wrote: > > Hi, > > Thanks for replying. > > > > That works spot-on! > > > > I was doing everything except the sqrt. > > Is it trivial to explain why this method works? > > Sure, the area of a disk is proportial to the radius squared. And so the > sqrt "undoes" this. > -Gil > > > > > Cheers for your time > > Zaf > > > > > > -----Original Message----- > > From: Gil Gribb [mailto:gg...@ma...] > > Sent: 25 October 2000 15:14 > > To: gda...@li... > > Subject: Re: [Algorithms] It's all Random Numbers > > > > > > > > > > > Hi All, > > > Does anyone know a fast way of calculating 2D points inside a > > > unit-disc, in a way that leads to a roughly even distribution? > > > > Well, the usual way is to just generate points in [-1,1]x[-1,1] and just > > throw away points that are outside the disk. But, I think this will work > > too: > > > > angle = 2 pi random() > > r = sqrt(random()) > > > > x= r cos(angle) > > y= r sin(angle) > > > > -Gil > > _______________________________________________ GDAlgorithms-list mailing list GDA...@li... http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list __________________________________________________________ This mail has been scanned for all known viruses by UUNET delivered through the MessageLabs Virus Control Centre. __________________________________________________________ This mail has been scanned for all known viruses by UUNET delivered through the MessageLabs Virus Control Centre. |