HPB>>XYZ conversion and atan2
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 10/11/2004 at 13:31, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.100
Platform:
Language(s) : C.O.F.F.E.E ;---------
Hi
Just wanted to post this somewhere since it needed me much time to implement this stuff on my own, but it seems to work now. There are lot's of angle configurations if you want to export to another coordinate system (XYZ YZX XZY...). Hope this is usefull for someone - likely to someone who want to write an exporter in COFFEE like I did.If you need another rotation combination, go to http://magic-software.com/ , they offer a paper on converting euler angles. Quite usefull other stuff, too.
The following code returns a XYZ rotation vector in degrees (not HPB!) for a right handed coordinate system - if you need it lefthanded you can try to negate the X angle (should work). The passed parameter has to be a normalized local matrix.
// Atan2 conversion similiar to the java/C implementation // a quick implementation - don't know if it's bugfree atan2(x,y) { var value = 0; if (y==0) { if (x<0) return -PI05; else return PI05; } value = atan(x/y); if (y<0) { if (x>0) value +=PI; else value -= PI; } return value; } // converts a rotation by a matrix (has to be a normalized local matrix) to XYZ rotation // instead of HPB, which is required for some export formats convertRotation(matrix) { var v1 = matrix->GetV1(); var v2 = matrix->GetV2(); var v3 = matrix->GetV3(); var thetaY = asin(v1.z),thetaX=0,thetaZ=0; if (thetaY<PI05) { if (thetaY>-PI05) { thetaX = atan2(-v2.z,v3.z); thetaZ = atan2(-v1.y,v1.x); } else { thetaX = -atan2(v2.y,v2.x); thetaZ = 0; } } else { thetaX = atan2(v2.x,v2.y); thetaZ = 0; } return vector(-thetaX,thetaY,thetaZ)*180/PI; }