문제

Input: two multidimensional (for example dim=8) vectors a and b.

I need to find out the "directed" angle (0-2*Pi, not 0-Pi) between those vectors a and b. And if they are not parallel I need to rotate vector b in plane a,b by "directed" angle L. If they are parallel, plane does not matter, but angle of rotation is still the same L.

For 2d and 3d this is quite easy, but for more dimensions I am lost, I didn't find anything on google, and I prefer using some already proved&tested equations (avoiding errors introduced by my calculations :-D).

Thank you in advance for tips, links, etc.

도움이 되었습니까?

해결책

I believe you should work on the plane generated by your vectors a and b. The code will then be the same regardless of the dimension (btw, the dimension of the vectors is by definition the dimension of the space).

You can do that by orthogonalizing (a,b) as:

a' = a/||a||
b1 = b - (a'·b)a'  <-- scalar product denoted by ·
b' = b1/||b||

Now you are on a plane with an orthonormal basis and should be back in business. The coordinates of b in that basis is (a'·b,b'·b). For a it is similarly (||a||,0). When you want to go back to the ambient space, simply write your vector with coordinates (x1,x2) as x1 a' + x2 b'.

I hope the math notation is not too confusing.

다른 팁

You may find this paper useful: Rotations for N-Dimensional Graphics by AJ Hanson. There's also this paper: General n-Dimensional Rotations. You can also check out this forum thread where a bunch of people try to work it out. And here's yet another paper: On the Rigid Rotation Concept in n-Dimensional Spaces. Must. Stop. Googling.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top