Jump to content
  • Advertisement
Sign in to follow this  
chad_420

How can I generate random 3d points?

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Yes (in terms of better 'quality' random numbers), but most likely the difference won't be noticable. What do you mean 'having trouble'? Just do:
const int RANGE = 5; //generate points with all coordinates between -5 and 5

point.x = 2.0f * ((float)rand() / MAX_RAND) - 0.5f) * RANGE;
point.y = 2.0f * ((float)rand() / MAX_RAND) - 0.5f) * RANGE;
point.z = 2.0f * ((float)rand() / MAX_RAND) - 0.5f) * RANGE;

Share this post


Link to post
Share on other sites
Do you want vectors with a length of 1 and a uniform distribution?

I forgot the formula for a sphere, but for a circle you pick a random angle and pick a radius using "max radius * sqrt(random(0.0, 1.0))" presuming random gives a uniform distribution.

Share this post


Link to post
Share on other sites
Quote:
Original post by Extrarius
Do you want vectors with a length of 1 and a uniform distribution?

I forgot the formula for a sphere, but for a circle you pick a random angle and pick a radius using "max radius * sqrt(random(0.0, 1.0))" presuming random gives a uniform distribution.


To generalize to n dimensions, the easiest (but probably not fastest) way is to pick a random value for each direction using a normal (i.e. Gaussian) distribution, and then normalize the result.

To generate such distributions, [google] "Polar Box-Mueller".

Share this post


Link to post
Share on other sites
Using Halton sequences is generally the best way to distribute points because it "fills the space" in an efficient manner. It is used for Quasi-MonteCarlo techniques, including illumination problems in computer graphics. Here is the link to the theory and source code:

http://www.csit.fsu.edu/~burkardt/cpp_src/halton/halton.html

-cb

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!