Random Point Distribution Problems
For a particle engine I need to randomly distribute points within a maximum spread.
My method is this:
However it doesn't seem to be working, so are there any problems with how I am doing it?
Is there any better method?
My method is this:
Code:
for each particle in particleArray do:
particle.x=particle.x+randomFrom0To1()*spread;
particle.y=particle.y+randomFrom0To1()*spread;
particle.z=particle.z+randomFrom0To1()*spread;
However it doesn't seem to be working, so are there any problems with how I am doing it?
Is there any better method?
What are you trying to achieve, and in what way does that implementation fall short of the intended result?
The main thing that pops out to me is that if your random function does what its name implies, you won't get any negative numbers, so you may want to do ((randomFrom0To1() - 0.5) * 2) instead. With more context, we'd probably be able to give you a better answer...
The main thing that pops out to me is that if your random function does what its name implies, you won't get any negative numbers, so you may want to do ((randomFrom0To1() - 0.5) * 2) instead. With more context, we'd probably be able to give you a better answer...
I already figured this one out, it had to do with me not taking into consideration that intValue%100/100 will always give 0 as there is no fractional part and it is not implicitly made float (Argh!!! The perils of being high on floats! Hah ha...).
Because I'm slightly bored:
You may also want to consider incorporating some form of a distribution function, probably Gaussian, to give your particle system a more realistic look.
Glad you fixed your problem, though!
You may also want to consider incorporating some form of a distribution function, probably Gaussian, to give your particle system a more realistic look.
Glad you fixed your problem, though!
"Who's John Galt?"