matrix - JavaFX 8 Transform to pitch, yaw and roll rotation angles -
implementing answer this thread have code translates deltayaw, deltaroll , deltapitch angles 1 angle , rotates node around it. angles taken parameters momentary changes of angles since giving whole angles ignore changes in orientation.
public static void matrixrotate(group n, double deltaroll, double deltapitch, double deltayaw){ double a11 = math.cos(deltaroll)*math.cos(deltayaw); double a12 = math.cos(deltapitch)*math.sin(deltaroll)+math.cos(deltaroll)*math.sin(deltapitch)*math.sin(deltayaw); double a13 = math.sin(deltaroll)*math.sin(deltapitch)-math.cos(deltaroll)*math.cos(deltapitch)*math.sin(deltayaw); double a21 =-math.cos(deltayaw)*math.sin(deltaroll); double a22 = math.cos(deltaroll)*math.cos(deltapitch)-math.sin(deltaroll)*math.sin(deltapitch)*math.sin(deltayaw); double a23 = math.cos(deltaroll)*math.sin(deltapitch)+math.cos(deltapitch)*math.sin(deltaroll)*math.sin(deltayaw); double a31 = math.sin(deltayaw); double a32 =-math.cos(deltayaw)*math.sin(deltapitch); double a33 = math.cos(deltapitch)*math.cos(deltayaw); double d = math.acos((a11+a22+a33-1d)/2d); if(d!=0d){ double den=2d*math.sin(d); point3d p= new point3d((a32-a23)/den,(a13-a31)/den,(a21-a12)/den); rotate r = new rotate(); r.setaxis(p); r.setangle(math.todegrees(d)); n.gettransforms().add(r); transform = n.getlocaltoscenetransform(); n.gettransforms().clear(); n.gettransforms().add(all); } }
(i'm using rotate because need rotate object around origin, not center)
now creates problem i'm no longer able actual pitch, roll , yaw angles.
i used keep track of them (which doesn't take account changing orientation):
roll +=deltaroll; pitch += deltapitch; yaw += deltayaw;
and later i've come this, bit more accurate, doesn't track changes occur if angles not directly modified(inserted after n.gettransforms().add(all) in main snippet):
roll+= math.todegrees(d)*((a32-a23)/den); pitch += math.todegrees(d)*((a13-a31)/den); yaw += math.todegrees(d)*((a21-a12)/den);
i've been searching around solutions , found this answer supposed give angle final transform haven't been able working angles.
double xx = n.getlocaltoscenetransform().getmxx(); double xy = n.getlocaltoscenetransform().getmxy(); double roll = math.atan2(-xy, xx);
again i'm trying full angles (composited out of transforms made delta angles in different orientations) relative scene's coodrdinate system. i'm bad @ great.
if want pitch, yaw , roll angles @ stage after several rotations, can them transformation matrix of 3d model.
if have @ transformation matrix after several rotations:
transform t = model3d.getlocaltoscenetransform(); system.out.println(t);
you'll see this:
transform [ 0.9034731871219395, -0.4260296991535005, -0.04727468234587054, 1.4044414829046357 0.3743586809560477, 0.837958815679334, -0.39709016761704913, 0.5234811188037405 0.2087864414768669, 0.3410626315861443, 0.9165612381019399, -1.1277640590168572 ]
if want angles, need compare matrix 1 answer:
as have stated, roll angle can use t.getmxx()
, t.getmyx()
:
double roll = math.atan2(-t.getmyx(),t.getmxx());
now, pitch, can use t.getmzy()
, t.getmzz()
in same way:
double pitch = math.atan2(-t.getmzy(),t.getmzz());
finally, yaw, use t.getmzx()
, t.getmzy()
, t.getmzz()
:
double yaw = math.atan2(t.getmzx(),math.sqrt(t.getmzy()*t.getmzy()+t.getmzz()*t.getmzz()));
this give above matrix angles looking (in radians):
roll: -0.39281984604895126 pitch: -0.356235553820928 yaw: 0.21033388848106072
Comments
Post a Comment