How to get the absolute rotation of a Node in JavaFX

限于喜欢 提交于 2019-12-11 04:16:20

问题


In JavaFX the rotateProperty of a Node provides me with its rotation in degree relative to its parent. Is there a way to get the absolute rotation in degree, either relative to the Scene or the Screen?

For example, is there a way to calculate the angle from the Transform object of a Node i can get from getLocalToSceneTransform()?


回答1:


So, i did the math myself, and for my case i either get the rotation in Radians via:

double xx = myNode.getLocalToSceneTransform().getMxx();
double xy = myNode.getLocalToSceneTransform().getMxy();
double angle = Math.atan2(-xy, xx);

or

double yx = myNode.getLocalToSceneTransform().getMyx();
double yy = myNode.getLocalToSceneTransform().getMyy();
double angle = Math.atan2(yx, yy);

In both cases this can be converted to 360-degrees:

angle = Math.toDegrees(angle);
angle = angle < 0 ? angle + 360 : angle;



回答2:


The question isn't really well defined, since different Nodes in the Scene graph are potentially rotated about different axes.

The getLocalToSceneTransform() method will return a Transform representing the transformation from the local coordinate system for the node to the coordinate system for the Scene. This is an affine transformation; you can extract a 3x4 matrix representation of it relative to the x- y- and z-axes if you like.



来源:https://stackoverflow.com/questions/23741574/how-to-get-the-absolute-rotation-of-a-node-in-javafx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!