[英]How to apply a transformation to a shape in JavaFX?
如果您只想进行旋转,只需将值相加即可。 rotate
是“绝对”旋转,而不是相对旋转。 如果要连接不同的转换,我建议使用Transform
并将它们添加到节点的transform
列表中。
至于查找坐标:您可能对父节点中的坐标感兴趣。 您可以使用Node.localToParent
从本地坐标中获取这些:
@Override
public void start(Stage stage) throws IOException {
Polygon p = new Polygon(0,0,0,100,50,50);
p.getPoints(); // output before : 0,0,0,100,50,50
p.getPoints(); // output after: 0,0,0,100,50,50
StackPane root = new StackPane(p);
Scene scene = new Scene(root, 500.0, 400.0);
scene.setOnMouseClicked(evt -> {
// add rotation and determine resulting position of (0, 0)
Rotate r = new Rotate(90, (0+0+50) / 3d, (0+100+50) / 3d);
p.getTransforms().add(r);
System.out.println("(0, 0) is now at " + p.localToParent(0, 0));
});
stage.setScene(scene);
stage.show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.