Board index » delphi » Generate random 3d vectors within angle around 3d vector?
Generate random 3d vectors within angle around 3d vector?
2005-05-12 09:30:27 AM
I have tried googling about this with not much luck - lots and lots of
pages to wade through :(
Hopefully this is a 'simple' question <G>
Given a direction 3d vector, how can I generate random vectors within a
'cone' formed by some max dot product angle between the direction vector and
the other vectors?
I can do this for, lets say a vertical direction vector no worries (see code
below), but I don't know how to apply this to any arbitarily pointing 3d
Function TParticleEmitter.GenVelocity: TVector3d;
d = 10;
h \ |d
o = max dot product angle around vector v
h = hypotenuse
d = some 'height' (can be anything)
r = max radius from v
h := d / Cos(o * PI / 180);
r := h * Sin(o * PI / 180);
a := Random * 360 * PI / 180; // random angle around circle looking down
at r length of triangle
r := Random * r; // take random radius between 0 and r
x := r * Cos(a);
z := r * Sin(a);
Result := Normalise(Point3d(x,d,z));
If anyone can help me, it would be excellent :)
"The plastic veneer of civilization is easily melted in the heat of the
moment" - Paul Nicholls.
Remove ".NOSPAM" to reply.