Board index » delphi » Generate random 3d vectors within angle around 3d vector?
Paul Nicholls
Delphi Developer |
Generate random 3d vectors within angle around 3d vector?2005-05-12 09:30:27 AM delphi182 Hi all, 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 vector... Function TParticleEmitter.GenVelocity: TVector3d; Const d = 10; Var x,z,h,a,r: Single; Begin { r v -------- \ | \ | \ | h \ |d \ | \o| \| 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)); End; If anyone can help me, it would be excellent :) Cheers, Paul. "The plastic veneer of civilization is easily melted in the heat of the moment" - Paul Nicholls. XXXX@XXXXX.COM Remove ".NOSPAM" to reply. |