What is euler rotation

transform.Rotate(x, y, z);  
Copy the code

The above is a common representation of rotation in Unity. The three components x, y and z are euler angles, which are the rotation angles around the x, y and Z axes respectively.

Static Euler Angle

The so-called static Euler Angle is that its axis of rotation uses a stationary reference frame. Such as:

transform.Rotate(new Vector3(0, 10, 0), Space.World); // The object is rotated 10 degrees around the y axis of the world coordinate systemCopy the code

The rotation Angle of the object’s axis around the world coordinate system is the static Euler Angle. There is also a case where the rotation Angle of the child object about its parent’s coordinate system is also the static Euler Angle (that is, the rotation value in the Transform component of the Unity editor, which displays a rotation axis that is neither the world coordinate system nor the local coordinate system. The rotation axis of the transform in the editor is the coordinate axis of the parent node.

Dynamic Euler Angle

The dynamic Euler Angle, using the rigid body itself as a reference frame, will rotate as the rigid body rotates. Such as:

transform.Rotate(new Vector3(0, 10, 0), Space.Self); // The object rotates 10 degrees about the Y-axis of its coordinate systemCopy the code

The rotation Angle of the object’s axis around its coordinate system is the dynamic Euler Angle.

The relationship between the two

Static euler Angle and dynamic Euler Angle can be transformed into each other. For specific transformation, please refer to this article. The conclusion is that rotation in space-world with z-x-y converging rotation angles (X, Y, Z) is equivalent to sequential rotation (0, Y, 0), (X, 0, 0), (0, 0, Z) in space-self. Such as:

privatevoid Rotate_World(float x, float y, float z) {  
    transform.Rotate(x, y, z, Space.World);  
}  
privatevoid Rotate_Self(float x, float y, float z) {  
    transform.Rotate(0, y, 0, Space.Self);  
    transform.Rotate(x, 0, 0, Space.Self);  
    transform.Rotate(0, 0, z, Space.Self);  
}  
Copy the code

The above two pieces of code are equivalent.

Universal joint deadlock phenomenon

We have understood what dynamic euler Angle and static Euler Angle are, and they can be converted to each other, but only dynamic Euler Angle has universal joint deadlock phenomenon, static Euler Angle does not produce universal joint deadlock, explained as follows. If the object coordinate system A and the world coordinate system B coincide, the object coordinate system A first rotates 50 degrees around the Y axis of A to obtain the new object coordinate system C (before the rotation, the Y axis of A and B are still in the same plane, from the view of the world coordinate system B, the object does rotate around the Y axis), And then the object coordinate system in orbits around the x axis C C D 90 degree to get a new object coordinate system (before the x axis C and B is still in the same plane, from the world coordinate system, B object does revolve around the x axis), we discover a new object coordinate system D Z axis and B Y axle load and the world coordinate system, Then we rotate the object frame D by 10 degrees about the Z axis of D. From the point of view of the world frame B, it seems to be rotating about the Y axis, as if an axis is missing. This is the universal joint deadlock.

How do I create a universal joint deadlock

As can be seen from the above process, to produce universal joint lock, only 90 degrees rotation is required for the coordinate axis in the middle of the ordination, which will make the coordinate axes at the front and rear of the ordination collinear. For the z-X-y conventions used in Unity, this intermediate axis is the X-axis.

Why do quaternions solve universal joint deadlocks

The essence of euler rotation is to decompose rotation about any axis into rotation about x, y, and z, which leads to universal joint deadlocks. Quaternion rotation can be directly expressed as rotation about any axis. This can be seen through the representation of quaternions

Other good articles

  • I highly recommend this blog post as a small summary of this blog post.
  • Feng Lele god’s article, there are Euler rotation running process
  • Unity scripture, using the drawing method to prove the universal joint deadlock.
  • Correlation calculation of quaternions
  • Fundamentals of 3D Mathematics: Graphics and Game Development