- Home /
XYZ Rotation Matrix
Hello,
can somone tell me which lines are missing for a complete xyz rotation matrix?
x = Mathf.Cos(Radians) * Child.transform.localPosition.x - Mathf.Sin(Radians) * Child.localPosition.y;
y = Mathf.Sin(Radians) * Child.transform.localPosition.x + Mathf.Cos(Radians) * Child.localPosition.y;
Example video of current state: https://www.youtube.com/watch?v=P3N3gYSOwVU&feature=youtu.be
Answer by Bunny83 · Dec 05, 2019 at 10:26 PM
I'm not really sure what you're asking here. First of all you don't have a matrix here. You just carry out a single axis / plane rotation manually. There is nothing like a "complete xyz rotation matrix". First of all if you asking for how to create a combined rotation matrix which rotates around 3 axis (in 3 planes) using euler angles, there are many different ways how you could combine those rotations. The result would be completely different.
If you are interested in how Unity's eulerangles and rotation matrices look like, see my answer over here. If you have trouble understandinf matrices in the first place, you might want to have a look at my Matrix crash course.
You haven't said what you actually want to achieve. Why do you translate the local position of your child object manually?
The combined rotation matrix for all 3 eulerangles is quite complex. I still don't see any reason why you want to do this manually since Untiy provides us with the $$anonymous$$atrix4x4 struct and also with the Quaternion struct. However If you really want to know how Unity's euler angles rotation matrix looks like. Have a look at this:
sx = sin(Xrad); cx = cos(Xrad);
sy = sin(Yrad); cy = cos(Yrad);
sz = sin(Zrad); cz = cos(Zrad);
Y * X * Z
[ cy, 0, sy] [1, 0, 0] [cz,-sz, 0]
[ 0, 1, 0] * [0, cx,-sx] * [sz, cz, 0]
[-sy, 0, cy] [0, sx, cx] [ 0, 0, 1]
[ cy, sx*sy, sy*cx] [cz,-sz, 0]
[ 0, cx ,-sx ] * [sz, cz, 0]
[-sy, sx*cy, cx*cy] [ 0, 0, 1]
[ cy*cz + sx*sy*sz,-cy*sz + sx*sy*cz, sy*cx]
[ cx*sz , cx*cz ,-sx ]
[-sy*cz + sx*cy*sz, sy*sz + sx*cy*cz, cx*cy]
nx = ox*( cy*cz + sx*sy*sz) - oy*(cy*sz + sx*sy*cz) + oz*(sy*cx);
ny = ox*( cx*sz ) + oy*(cx*cz ) - oz*(sx);
nz = ox*(-sy*cz + sx*cy*sz) + oy*(sy*sz + sx*cy*cz) + oz*(cx*cy);
I've included the intermediate steps of combining the 3 rotation matrices into one. (ox,oy,oz) is the original vector while (nx,ny,nz) is the rotated vector.
Thanks for your answer @Bunny83 . You know I am just a bit curious about I$$anonymous$$ especially the 6 DOF Arm from $$anonymous$$uka with spherical wrist atm and I don't want to use libraries.
So I've watched your TRS $$anonymous$$atrix functions but I don't know how to use them to rotate my child object localPosition in the video
Thats the link for your functions id like to rotate my child object: https://answers.unity.com/questions/1435216/are-these-rotation-matrices-right.html
Your answer

Follow this Question
Related Questions
RotateAround() faster than rotate 1 Answer
rotate around character 1 Answer
Rotate Around Object 2 Answers
How to rotate an object according to the camera's view? 1 Answer
rotation script in unity 3 Answers