# [webkit-dev] TransformationMatrix rotation code and floating-point precision

W. James MacLean wjmaclean at chromium.org
Tue May 15 07:57:03 PDT 2012

```If it's computing theta/2, perhaps the trig formulas are for converting
from a quaternion to a matrix? Does it look like the matrix in the

http://en.wikipedia.org/wiki/Rotation_operator_(vector_space)

On Mon, May 14, 2012 at 10:30 PM, Shawn Singh <shawnsingh at chromium.org>wrote:

>
> Hi all,
>
> I'm looking at TransformationMatrix::rotate3d(rx, ry, rz).  This code does
> something indirect, and I don't understand why.  Instead of initializing
> each rotation using sin(theta), cos(theta),  the code computes theta/2, and
> then uses trig identities to initialize the rotation matrix.
>
> I checked really quickly with fprintf, and it seems like we could actually
> gain 1-2 bits of precision if we avoid doing this, and use sin(theta) and
> cos(theta) directly.  In the current code, more error seems to accumulate
> due to sin^2 (theta / 2).  Squaring that value instantly increases the
> error inherent in the computation.  I cannot think of any valid reason that
> this code uses those trig identities instead of directly using sin and cos.
>  Does anyone else know why?  Is this worth changing to gain some precision?
>
> On a secondary note, its also fishy that we are freely mixing floats and
> doubles in the rotation code.  But, I don't think that is as significant
> error accumulation as the sin^2.
>
> Thanks,
> ~Shawn
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20120515/5e013bd6/attachment.html>
```