Re: [css3-transforms] Pseudo code for matrix decomposing

On Feb 14, 2012, at 10:03 AM, Dirk Schulze wrote:

> Hi,
> 
> At the moment the CSS Transforms specification (http://dev.w3.org/csswg/css3-transforms/) provides some pseudo code to decompose 4x4 matrices. The decomposing is needed for transitions and animations of transforms. The current code uses euler angles for rotate. This might be easier to understand. Nevertheless, the WebKit implementation uses quaternion[1][2] for decomposing. Quaternion is another number system that extends the complex numbers. It helps avoiding some mathematical singularities like the hairy ball theorem[1].
> 
> Should the CSS Transform specification add a normative section that implementations should use quaternion? Should the pseudo code get updated with a maybe more complex quaternion version? Should the animation section get updated how to deal with quaternion?

Quaternions are almost always the preferred method of decomposing rotations if your intent is to do animations. Euler angles are prone to gimbal lock [1] which makes animation undefined when passing through certain angles. Quaternions don't have this problem and can be animated without ambiguity using a slerp function [2]. So if we do this it will require a small change to the unmatrix pseudocode and the addition of some pseudocode for slerp.

Webkit uses quaternions and a slerp function. 

[1] http://en.wikipedia.org/wiki/Gimbal_lock
[2] http://en.wikipedia.org/wiki/Slerp

-----
~Chris
cmarrin@apple.com

Received on Tuesday, 14 February 2012 18:29:21 UTC