Advertisement

Random vector in cone

Started by January 15, 2003 07:17 AM
0 comments, last by andy maddison 22 years, 1 month ago
Can anyone tell me how to get a random vector which lies within the cone defined by a given vector and an angle? Cheers.
If the length is fixed, look into spherical coordinates; it''s the simplest way to do it. If not, here''s another way to do what you want: First, find the maximum length that your vector can have (call it l), and generate a random vector within the cube of dimensions 2l X 2l X 2l. Then, check if this vector is inside the cone, by comparing its length to l, and by finding the angle between the vector and the axis of the cone, using the dot product. If the vector is not inside the cone, discard it and generate a new one inside the 2l cube. Rince and repeat until your vector is valid.

This is the general idea. If you have a problem with the specifics, we can provide more details.

HTH,

Cédric

This topic is closed to new replies.

Advertisement