Particle Systems and a 'Cone of Deviation'

first off i want to say that i’m not sure whether or not this message belongs in the beginner’s forum… but since i’m a beginner i figured what the hell…

my question is almost completely mathmatical in nature, but i believe it has an application in particle systems and other quasi-chaotic systems.

here it is: in designing a particle system that i would like to code, i ran into a snag, how can i have a standard velocity for the system to move with, yet have each individual particle move with a velocity similar but slightly deviant to the system’s standard velocity…

after a bit of thought, i came up with the idea of a ‘Cone of Deviation’ (hence the subject of this post) the idea is basically this:

we know our system’s velocity vector, call it sysVelocity, and we know an angle of deviation from this velocity, call it theta, that defines a cone around the sysVelocity vector in which the velocity of each individual particle should fall.

hmm… that description is kind of hazy… a picture would do it better…


/ ) <------------- theta
*-----------> <- sysVelocity vector
\ ) <------------- theta


and the * is the position of the system

ok… now take the top and bottom vectors (which define the edges of the cone of deviation) and spin them in 3d around sysVelocity… those of you who have a good imagination now see the ‘Cone of Deviation’ (i hope)

alright… so, this is my question (finally), how do i go about picking a random velocity vector that is inside this cone of deviation and assigning it to a particle?

i hope that i explained this properly… i might be going at this in an incredibly over-complex manner… but this is the only way i can think of to do this… if i just use a single velocity vector for the whole system, i get a line of particles all flowing in the same path… if i pick completely random velocities then i get a type of starburst…

thanks in advance for any insight!

----brian ploeckelman

UPDATE:: with a bit more thought i came up with this as a method… i’m just a bit hazy on how to mathmatically implement this idea about how to get our random velocity out of the cone:

project sysVelocity by 0 <= angle of projection <= theta
take the projected vector and rotate it around sysVelocity by a random angle 0-360…

unfortunately my linear algebra skills aren’t quite up to snuff… so i’m lost on how to mathmatically implement this idea

oh… by the way sorry for that messed up ascii figure… i hope the idea is still clear

thanks again…

—brian ploeckelman

Ok, that’s exactly what I did for my particle engine, so here is some code :

r1 = (double)rand()/RAND_MAX;
alpha = thetar1 + thetaMax(1-r1);

r2 = (double)rand()/RAND_MAX;
beta = phir2 + phiMax(1-r2);
vx = speed*cos(beta)cos(alpha);
vy = speed
vz = speed

Fist you can see that there is not one but two angles : alpha and beta that are respectively ranged from theta and thetaMax (phi and phiMax).
r1 and r2 are random numbers ranged from 0 to 1.
speed is, well a pseudo norm of your velocity vector.
So (vx,vy,vz) is what you where asking for …

Check my web page

[This message has been edited by julien (edited 12-01-2000).]