【发布时间】:2015-06-13 09:32:29
【问题描述】:
实现this thread 的答案我有这段代码可以将 deltayaw、deltaroll 和 deltapitch 角度转换为一个角度并围绕它旋转一个节点。作为参数的角度是角度的瞬间变化,因为给出整个角度会忽略方向的变化。
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);
}
}
(我使用旋转是因为我需要始终围绕原点而不是中心旋转对象)
现在这产生了一个问题,因为我不再能够获得实际的俯仰角、滚动角和偏航角。
我以前是这样跟踪它们的(不考虑方向的变化):
roll +=deltaroll;
pitch += deltapitch;
yaw += deltayaw;
后来我想出了这个,它更准确一点,但是如果没有直接修改角度(插入在 n.getTransforms().add(all) 之后),则不会跟踪发生的变化在主 sn-p):
roll+= Math.toDegrees(d)*((A32-A23)/den);
pitch += Math.toDegrees(d)*((A13-A31)/den);
yaw += Math.toDegrees(d)*((A21-A12)/den);
我一直在寻找解决方案,发现 this answer 应该给出最终变换的角度,但我无法让它适用于所有角度。
double xx = n.getLocalToSceneTransform().getMxx();
double xy = n.getLocalToSceneTransform().getMxy();
double roll = Math.atan2(-xy, xx);
我再次尝试获得的是相对于场景的坐标系统的全角度(由不同方向的增量角度进行的变换合成)。我在这方面真的很糟糕,所以所有的帮助都会很棒。
【问题讨论】:
标签: matrix 3d rotation javafx-8