JavaFX的8变换俯仰

JavaFX的8变换俯仰

本文介绍了JavaFX的8变换俯仰,偏航和滚动旋转角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实现从this螺纹我有这个code表示平移deltayaw,deltaroll和deltapitch角度成一个角度和旋转它周围的节点。被视为参数的角度角度,因为给人的整体角度会忽略的变化,方向瞬间的变化。

Implementing the answer from this thread I have this code that translates the deltayaw, deltaroll and deltapitch angles into one angle and rotates a node around it. The angles that are taken as the parameters are momentary changes of angles since giving the whole angles would ignore the 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 all = n.getLocalToSceneTransform();
        n.getTransforms().clear();
        n.getTransforms().add(all);
    }
}

(我使用的旋转,因为我需要一直旋转物体周围的原点,而不是中心)

(I'm using rotate because I need to always rotate the object around the origin, not the center)

现在这将创建一个问题,因为我不再能获得实际的俯仰,滚转和偏航角。

Now this creates a problem as I'm no longer able to get the actual pitch, roll and yaw angles.

我来跟踪它们,像这样(不考虑改变方向):

I used to keep track of them like this (which doesn't take into account the changing orientation):

roll +=deltaroll;
pitch += deltapitch;
yaw += deltayaw;

后来我想出了这一点,这是更准确一点,但不跟踪如果角度不直接修改所发生的变化(在n.getTransforms()后插入。添加(全部)在主代码段):

And later I've come up with this, which is a bit more accurate, but doesn't track the changes that occur if the angles are not directly modified(inserted after the n.getTransforms().add(all) in the main snippet):

roll+= Math.toDegrees(d)*((A32-A23)/den);
pitch += Math.toDegrees(d)*((A13-A31)/den);
yaw += Math.toDegrees(d)*((A21-A12)/den);

我一直在寻找周围的解决方案,并找到this回答这是应该给的角度从最终的变换,但我一直没能得到它的工作的各个角度。

I've been searching around for solutions and found this answer which is supposed to give the angle from the final transform but I haven't been able to get it working for all angles.

double xx = n.getLocalToSceneTransform().getMxx();
double xy = n.getLocalToSceneTransform().getMxy();
double roll = Math.atan2(-xy, xx);

再次什么我想要得到的是全角(合成从增量的角度在不同的方向做了变换)相对于场景的coodrdinate系统。我真的不擅长这个,因此所有的帮助将是巨大的。

Again what I'm trying to get are the full angles (composited out of the transforms made from the delta angles in different orientations) relative to the scene's coodrdinate system. I'm really bad at this so all help would be great.

推荐答案

如果你想获得的俯仰,偏航和滚动角在任何阶段,几个旋转后,可以从三维模型的变换矩阵得到他们。

If you want to get the pitch, yaw and roll angles at any stage after several rotations, you can get them from the transformation matrix of the 3D model.

如果你看一下变换矩阵几个旋转后:

If you have a look at the transformation matrix after several rotations:

Transform T = model3D.getLocalToSceneTransform();
System.out.println(T);

你会看到这样的内容:

you'll see something like 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 you want the angles, you just need to compare this matrix with this one from this answer:

正如你已经指出的那样,拿到滚动角,您可以使用 T.getMxx() T.getMyx()

As you have already stated, to get the roll angle you can use T.getMxx() and T.getMyx():

double roll = Math.atan2(-T.getMyx(),T.getMxx());

现在,在球场上,你可以使用 T.getMzy() T.getMzz()的以同样的方式:

Now, for the pitch, you can use T.getMzy() and T.getMzz() in the same way:

double pitch = Math.atan2(-T.getMzy(),T.getMzz());

最后,偏航,使用 T.getMzx() T.getMzy() T.getMzz()

double yaw = Math.atan2(T.getMzx(),Math.sqrt(T.getMzy()*T.getMzy()+T.getMzz()*T.getMzz()));

这将给予上述矩阵你正在寻找(弧度)角度:

This will give for the above matrix the angles you are looking for (in radians):

roll: -0.39281984604895126
pitch: -0.356235553820928
yaw: 0.21033388848106072

这篇关于JavaFX的8变换俯仰,偏航和滚动旋转角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 17:57