views:

74

answers:

1

How do I calculate the Rotation in Radians around Z-axis by giving a CATransform3D struct as the input?

basically what I need is the other way round of CATransform3DMakeRotation.

+2  A: 
Nader
Be sure to use atan2 and not atan as the later will not give an angle in the correct quadrant.
Nader
Thank you Nader, before your answer, I had resorted back to using CALayer's affineTransform property convert the Transform3D into an AffineTransform and then get the angle out of it from this calculation:http://stackoverflow.com/questions/2051811/iphone-sdk-cgaffinetransform-getting-the-angle-of-rotation-of-an-objectNow I know, how to calculate directly from Transform3D. Thanks!
ravinsp
Yeah I learned about this back in first year uni and can remember asking my friend "why the he'll do we need to know this"
Nader
You can calculate the angle from an affine transform too using atan2(transform.b, transform.a), the maths still holds true for a z-axis rotation
Nader