0

I have a 3D unity vector pointing in a certain direction. Now I want to get a new unity vector which is 45 degrees tilted from the direction of that vector, in which direction exactly has to be random. Does anyone know a way to compute that new vector?

(Alternatively, this may be expressed as the rotation of a 3D point around the origin in a random direction by 45 degrees.)

To remove the 'random' component: I am happy if I can find ANY vector that is 45 degrees tilted from my old vector, because then I might be able to rotate the end point of that vector a random distance around the old vector.

4

1 回答 1

1

Let's say you have a vector v1. First, you should find a vector v2 which is perpendicular to v1. Then the vector you want to find out is half between v1 and v2, that is v3 = norm(norm(v1)+norm(v2)). And how to find v2? You can take a cross product of v1 and any vector which is not parallel to v1. So you can do something like this:

v2 = cross(v1, (1,0,0));
if (dot(v2, v2) < 0.001) v2 = cross(v1, (0,1,0));
v3 = normalize(normalize(v1)+normalize(v2));

Finally, the angle between v1 and v3 is 45 degrees.

于 2012-05-13T23:03:14.103 回答