1

Let's assume that I have a vector, say vectorA=[1,2,3,4]. I can rotate vectorA by some angle alpha in some direction so that it becomes vectorB=[6,7,8,9] after the rotation. Given the two vectors, vectorA and vectorB, how can I work out the angle and direction of rotation?

For the angle, that's simple enough: I can use any one of the answers to this question.

For the direction (clockwise/counter-clockwise), I am a little clueless. I know how to do it in 2 dimensions and in 3 dimensions. How do I do this for N dimensions, i.e. 4D and beyond?

FirefoxMetzger
  • 2,880
  • 1
  • 18
  • 32
  • If you know the rotation plane you can project those ND vectors to 2D and use standard 3D cross product checking the sign of z component or do `CW/CCW=sign(dot(cross(v0,v1,v2...),axis))` However if you do not know the rotation plane.. The problem is that the plane normal is computed by cross product which have `n-1` input vectors and you have just 2 for 4D (missing one)... However there where also formula using `dot` instead of cross which IIRC worked in ND with 2 operands however I can not find the formula nor it would help you as the normal would not be the axis you need most of the time... – Spektre Jun 12 '21 at 07:02
  • @Spektre Thanks for the comment! Getting the plane of rotation is easy, actually. Knowing that `vectorA` becomes `vectorB` fully defines it. However, there are `N-2` dimensions left after doing this. In 3D that's `3-2=1` giving you the convenient notion of a normal vector and I can use the formula you suggested. In 4D that would be `4-2=2`, so I would have to choose 2 normal vectors? How does that work? – FirefoxMetzger Jun 12 '21 at 07:25
  • If you got the plane ... then 1. construct 2 unit perpendicular vectors to each other `U,V` inside that plane. Then convert any `P` (point/vector) to 2D uv mapping `u=dot(P-P0,U); v=dot(P-P0,V);` where `P0` is any point inside the plane... from this `(u,v)` is just 2D vector. One of the `U,V` vectors might be your input vector other must be computed ... – Spektre Jun 12 '21 at 07:33
  • Finallyyyy I found the equation ... was sure it was near one of mine ND answers [How to generate a randomly oriented, high dimension circle in python?](https://stackoverflow.com/a/42339177/2521214) .... `P2 = P2 - dot(P1, P2)*P1; P2 = P2 / | P2 |` however beware I think if you use your input vectors then it will not work as their order would always match the cross ... so you would have to imply some assitional rules on which side the normal of plane should go – Spektre Jun 12 '21 at 07:45
  • You know like the view direction or something because if you look at the rotation from one side its CW and from the other CCW ... for example if it is related to some mesh you can use axis/normal that point outward from the mesh, or use camera view direction ... or whatever else you got – Spektre Jun 12 '21 at 07:59
  • How about rotating `vectorA` by `angle` in the rotation plane and checking if the result equals `vectorB`? If it does, the direction is positive, otherwise it's negative. – Bip901 Mar 02 '22 at 10:06
  • @Bip901 How would you go about finding the direction in which to rotate by `angle`? – FirefoxMetzger Mar 03 '22 at 08:32

0 Answers0