Axis-Angle->Euler Conversion
by Thomas -elfprince13- Dickerson · 02/13/2012 (9:45 pm) · 4 comments
#!/usr/bin/env python import math import sys def aa2e(axis_angle): axis = axis_angle[:-1] angle = axis_angle[-1] quat = [q * math.cos(angle/2) for q in axis] + [math.sin(angle/2)] s, t = math.sin(angle), 1 - math.cos(angle) x,y,z=axis z_comp = x * y * t + z * s if abs(z_comp) > 0.999: # singularity up north sign = cmp(z_comp, 0) bank = 0 heading = sign * 2 * math.atan2(x * math.sin(angle/2),math.cos(angle/2)) attitude = sign * math.pi/2 else: bank = math.atan2(x * s - y * z * t , 1 - (x**2 + z**2) * t) heading = math.atan2(y * s - x * z * t , 1 - (y**2+ z**2 ) * t) attitude = math.asin(z_comp) return (bank, heading, attitude) if __name__ == "__main__": print "(%.7f %.7f %.7f)" % aa2e([float(i) for i in sys.argv[1:5]])
example usage:
Quote:
[thomas@Bombadil] ~ $ axisangle_to_euler.py 0.707 0.707 0 3.14
(0.0000000 3.1393400 1.5707963)
About the author
C.S. PhD student at Brown University. Project lead for FreeBuild. Administrator, Cemetech tech community. Webmaster for the Village2Village Projects and the Vermont Sustainable Heating Initiative.

Torque Owner D Fasel
Game 3D