- Home /
Get the rotation matrix if you have the start and end position
Hello, I'm trying to get the needed rotation to get a small cube from a rubik's cube to the right position.
I made my rubik's cube positions like a matrix from -1 to 1 on the x,y and z axis.
Now my problem is, if I have for example the position (1,1,1) and the end position should be (-1,1,1) how can I get something like a rotation matrix that says I have to rotate 90° on the y-axis?
I also tried using the mathematics package but I can't find any soltuion.
Answer by jamesvhyde · Jul 22, 2020 at 09:50 PM
A rotation of 90° on the y-axis is most easily done using Euler angles. You can get a rotation in the form of a quaternion, and from there to a matrix, using code like this:
Quaternion rotation = Quaternion.Euler(0, 90, 0);
Matrix4x4 m = Matrix4x4.Rotate(rotation);
More info: Quaternions and rotation matrices.
Thanks for the awnser. $$anonymous$$y problem is that I have to find out which axis I have to rotate at what angle so how could I find out that a 90° rotation on the y-axis is needed to get from (1,1,1) to (-1,1,1)?
I see. Your problem is underdeter$$anonymous$$ed. There are two answers. Since the x value is changing, you can get there either by rotating around the y axis or around the z axis. They correspond to two different Rubik's Cube operations. Somehow you have to choose which one you want.
Your answer
Follow this Question
Related Questions
How to get a vector3 (postion) 1 unit away from another in the direction of a 3rd vector3? 2 Answers
How to get translation from matrix? 1 Answer
Please help, bullet drop is wrong at certain angles ? 0 Answers
Please help with some Vector math! :-) 1 Answer
Project a position onto a plane whose normal isn't at the origin. 2 Answers