c++ - Reversing RotateAxisAngle back to angles -
i'm trying figure out how reverse rotateaxisangle rotations around these arbitrary axes (or equivalent rotations yield same net rotation, doesn't have identical). know how it? i'm using mathgeolib, don't see opposite way, return angles axes, when have matrix.
here's forward direction code (rotateaxisangle mathgeolib):
float4x4 matrixrotation = float4x4::rotateaxisangle(axisx, toradian(rotation.x)); matrixrotation = matrixrotation * float4x4::rotateaxisangle(axisy, toradian(rotation.y)); matrixrotation = matrixrotation * float4x4::rotateaxisangle(axisz, toradian(rotation.z));
now want degrees, these arbitrary axes, in same order (well, pull off z, y, x), if did again, forward direction, yield same net rotations.
here's sample/matrix corresponding set of rotations posted above, if helps, on reversing it:
axisx: x 0.80878228 float y -0.58810818 float z 0.00000000 float rot axis: 30.000000 float axisy: x 0.58811820 float y 0.80877501 float z 0.00000000 float rot axis: 60.000000 float axisz: x 0.00000000 float y 0.00000000 float z 1.0000000 float rot axis: 40.000000 float
that forms matrix, stored file, , need retrieve rotations above axes (without info rotations used)
[4][4] [0x0] 0.65342271 float [0x1] -0.51652151 float [0x2] 0.55339342 float [0x3] 0.00000000 float [0x0] 0.69324547 float [0x1] 0.11467478 float [0x2] -0.71151978 float [0x3] 0.00000000 float [0x0] 0.30405501 float [0x1] 0.84856069 float [0x2] 0.43300733 float [0x3] 0.00000000 float [0x0] 0.00000000 float [0x1] 0.00000000 float [0x2] 0.00000000 float [0x3] 1.0000000 float
ok, i'm going take stab @ this. first answer xyz order of rotations. answer zyx order, know more how mathgeolib works.
mathgeolib represents position vectors column vectors v = [x y z 1]^t
^t
transpose operator flips rows columns (and vice versa). rotation matrices pre-multiply column vectors. if have matrix rx(s)
representing rotation around x-axis s degrees, rotation ry(t)
representing rotation y-axis t degrees, rotation rz(u)
representing rotation z-axis u degrees, , combine them , multiply v
rx(s) ry(t) rz(u) v
, we're applying z rotation first. can still work out angles combined matrix, it's formulas going different more common xyz order.
we have upper left blocks of rotation matrices follows. (the fourth row , column 0s except diagonal element 1; never changes in calculations follow can safely ignore.) mathgeolib appears use left-handed coordinates, rotation matrices are:
[1 0 0] [ cos t 0 sin t] [ cos u -sin u 0] rx(s) = [0 cos s -sin s], ry(t) = [ 0 1 0], rz(u) = [ sin u cos u 0] [0 sin s cos s] [-sin t 0 cos t] [ 0 0 1]
(note position of - sign in ry(t)
; it's there because think of coordinates in cyclic order. rx(s)
rotates y , z; ry(t)
rotates z , x; rz(u)
rotates x , y. since ry(t)
rotates z , x not in alphabetical order in cyclic order, rotation opposite in direction expect alphabetical order.
now multiply matrices in correct order. rx(s) ry(t)
is
[1 0 0][ cos t 0 sin t] [ cos t 0 sin t] [0 cos s -sin s][ 0 1 0] = [ sin s*sin t cos s -sin s*cos t] [0 sin s cos s][-sin t 0 cos t] [-cos s*sin t sin s cos s*cos t]
the product of rz(u)
is
[ cos t 0 sin t][ cos u -sin u 0] [ sin s*sin t cos s -sin s*cos t][ sin u cos u 0] = [-cos s*sin t sin s cos s*cos t][ 0 0 1] [ cos t*cos u -cos t*sin u sin t] [ sin s*sin t*cos u+cos s*sin u -sin s*sin t*sin u+cos s*cos u -sin s*cos t] [-cos s*sin t*cos u+sin s*sin u cos s*sin t*sin u+sin s*cos u cos s*cos t]
so can figure out angles follows:
tan s = -(-sin s * cos t)/(cos s * cos t) = m23/m33 => s = -arctan2(m23,m33) sin t = m13 => t = arcsin(m13) tan u = -(-cos t * sin u)/(cos t * cos u) = m12/m11 => u = -arctan2(m12,m11)
if implement calculations, need understand how matrix indexed in mathgeolib. indexing row major, mathematical notation, indexing starts @ 0 (computer style) rather @ 1 (math style) c++ formulas want are
s = -atan2(m[1][2],m[2][2]); t = asin(m[0][2]); u = -atan2(m[0][1],m[0][0]);
the angles returned in radians need converted degrees if desired. should test result in case when axes rotations z, y, , x in standard position (001), (010), , (100).
if reverse rotation non-standard axes, in example, problem becomes more difficult. however, think can done "change of coordinates". if our rotation mystery matrix matrixrotation
, believe can form "conjugate" matrix
m = coordinatechangematrix*matrixrotation*coordinatechangematrix^{-1}
and use above formulas. here coordinatechangematrix
matrix
[xaxis0 xaxis1 xaxis2 0] [yaxis0 yaxis1 yaxis2 0] [zaxis0 zaxis1 zaxis2 0] [ 0 0 0 1]
where rotation x-axis (xaxis0,xaxis1,xaxis2)
. in example numbers (0.808...,-0.588...,0)
. should make sure rotation matrix orthonormal, i.e., dot product of xaxis 1, dot product of xaxis axis 0, , same other axis. if coordinate change matrix not orthonormal, calculation might still work, don't know sure.
the inverse of coordinate change matrix can calculated using float4x4::inverseorthonormal
or if it's not orthonormal can use float4x4::inverse
mentioned don't know how work.
Comments
Post a Comment