Euler Angles
Euler angles describe the orientation of rigid body in a within a static coordinate system.“Any orientation can be decomposed into three elemental rotations”: x (yaw), y (pitch) and z (roll). These three elemental angles can then be concatenated to yield the desired orientation" (Kenwright, 2013, p. 4).
Because each angle is decomposed into elemental axis rotations, using Euler angles within an IK solution would make limiting specific joints degrees-of-freedom to explicit rotations straightforward.
In a 2D IK solution this would provide results as intended, though in a 3D IK solutions gimbal lock would have significant negative impact on the functionality of the algorithm.
Figure 1: no aligned axis, no Gimbal lock (Wikipedia Contributors, 2019) | Figure 2: aligned axis, Gimbal lock (Wikipedia Contributors, 2019) |
Gimball Lock
Gimbal lock restricts the system’s ability to rotate freely in three-dimensions.Its effect becomes more significant the closer the alignment between multiple elemental axes become. This is unavoidable due to the hierarchical relationship between each elemental axis (they rotate relative to their parent axis).
When axes are aligned they will act as though they are a single axis, restricting the system’s ability to rotate freely in three-dimensions.
Figure 3: Visualisation of axis alignment, producing gimbal lock (Wikipedia Contributors, 2019) |
Despite there being only two precise arrangements where true gimbal lock occurs, as multiple axes approach alignment small rotations of the gimbal platform require far larger motions of the surrounding gimbals. This limitation increases the closer to alignment gimbals are, fully locking when the ratio becomes infinite.
Singularities
In the context of an IK solution, elimination of potential gimbal lock contributes to eliminating the creation of singularities.If a joints rotation on one axis becomes aligned with another, it may not be able to appropriately apply a corrective rotation. Behaviour can be added to rotate the remaining free axis by 180 instantly to maintain the reach of the joint chain, though this creates extremely unnatural behaviours throughout the joint chain and may result in further gimbal lock/singularities elsewhere in the chain.
A way to avoid gimbal lock entirely would be to use quaternions to calculate rotation rather than Euler angles.
Quaternions
“A quaternion is an alternative mathematical entity used to represent rotation” (Lengyel, 2012, p. 80).To interpret complex numbers as points in 3D space, quaternions are four-dimensional. Each quaternion is formed of one real dimension and 3 imaginary dimensions (each a scalar number).
As quaternions are noncommutative they do not suffer gimbal lock (as Euler angles will). This makes them far more appropriate for use within an IK solution.
While I wish to continue developing my understanding of quaternion calculations, I don’t intend to create my own implementation of quaternions within this project, nor create my own mathematical solutions to calculate quaternion values. Instead I will make use of the methods provided by Unity.
Kenwright (2012, pp. 193-194) discusses angular constraints, recommending use of quaternions to represent any adjustment made to a rigidbody as every quaternion represents a unique orientation.
Kenwright (2012, pp.194-196) continues to discuss how differences in rotation between to quaternions can be compared by multiplying one quaternion by the inverse of another (as this is the same as the conjugate).
Comparing quaternions in this way could be used identify whether an angular constraint has been breached without the concern of gimbal lock.
Kenwright (2013, pp99-102) shows how a quaternion can be decomposed into two parts: the twist and swing components. While only briefly discussed, this separation of the quaternion components appears to be directly applicable to my joint-specific issue.
I will continue to work towards solving my constraint issues with this weeks remaining development time and if not solved will continue research next week, using the quaternion research above as a starting point.
Next Objectives
While I feel this research has made me more confident understanding the mathematics of rotations, despite investing significant time into looking I have struggled to find resources which discuss the problems I’m specifically trying to solve in an even vaguely related context.I will keep attempting to constrain CCD joint angles while I continue research, though feel progress may continue to be slow if I cannot find a more relevant explanation.
References
Kenwright, B. (2012). Game Physics. pp.192-197.
Kenwright, B. (2013). Game inverse kinematics. [Place of publication not identified]: CreatSpace, pp.5-9, 18-64, 89-94.
Lengyel, E. (2012). Mathematics for 3D Game Programming and Computer Graphics. 3rd ed. pp.463 - 467, 509 - 511.
Wikipedia Contributors. (2019). Available at: https://en.wikipedia.org/wiki/Quaternion [Accessed 29 Apr. 2019]
Bibliography
AERIAL ROBOTICS (2017). Euler Angles. Available at: https://www.youtube.com/watch?v=3Zjf95Jw2UE [Accessed 7 May. 2019]
Baker, M. (2017). Maths - Quaternions. [online] Euclideanspace.com. Available at: http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/index.htm [Accessed 6 May. 2019].
Euler (gimbal lock) Explained. (2009). [video] Directed by GuerrillaCG. Available at: https://www.youtube.com/watch?v=zc8b2Jo7mno [Accessed 29 Apr. 2019]
Gyroscopes and Gimbal Lock. (2014). [video] Directed by Smithsonian National Air and Space Museum. Smithsonian National Air and Space Museum. Available at: https://www.youtube.com/watch?v=7vpRPbPs8j4 [Accessed 5 May. 2019]
Jeremiah (2012). Understanding Quaternions. [online] 3D Game Engine Programming. Available at: https://www.3dgep.com/understanding-quaternions/ [Accessed 24 Apr. 2019].
Joyce, H. (2004). Curious quaternions. [online] plus.maths.org. Available at: https://plus.maths.org/content/curious-quaternions [Accessed 26Apr. 2019].
Unity Technologies (2019). Quaternions - Unity Learn. [online] Unity Learn. Available at: https://learn.unity.com/tutorial/quaternions# [Accessed 28 Apr. 2019].