How to get the absolute rotation of a Node in JavaFX

后端 未结 2 1876
孤城傲影
孤城傲影 2021-01-24 23:49

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

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-25 00:30

    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;
    

提交回复
热议问题