📅  最后修改于: 2020-10-14 01:51:38             🧑  作者: Mango
旋转可以定义为将物体旋转一定角度θ(θ)的过程。在JavaFX中,类javafx.scene.transform.Rotate表示Rotation变换。
该图说明了旋转变换。图像中显示的矩形沿Y轴旋转角度θ。矩形的坐标由于旋转而改变,而边缘保持相同的长度。
下表描述了该类的属性以及setter方法。
Property | Description | Setter Methods |
---|---|---|
angle | It is a double type property. It represents the angle of rotation in degrees. | setAngle(double value) |
axis | It is a object type property. It represents the axis of rotation. | setAxis(Point3D value) |
pivotX | It is a double type property. It represents the X coordinate of rotation pivot point. | setPivotX(double value) |
pivotY | It is a double type property. It represents the Y coordinate of rotation pivot point. | setPivotY(double value) |
pivotZ | It is a double type property. It represents the Z coordinate of rotation pivot point. | setPivotZ(double value) |
该类包含六个构造函数。
以下示例说明了旋转变换的实现。在这里,我们创建了两个矩形。一种填充为柠檬绿色,而另一种填充为深灰色。沿枢轴点坐标(100,300)将深灰色矩形旋转30度。
package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
public class RotateExample extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
// creating the rectangles
Rectangle rect1 = new Rectangle(100,100,200,200);
Rectangle rect2 = new Rectangle(100,100,200,200);
// setting the color and stroke for the Rectangles
rect1.setFill(Color.LIMEGREEN);
rect2.setFill(Color.DARKGREY);
rect1.setStroke(Color.BLACK);
rect2.setStroke(Color.BLACK);
// instantiating the Rotate class.
Rotate rotate = new Rotate();
//setting properties for the rotate object.
rotate.setAngle(30);
rotate.setPivotX(100);
rotate.setPivotY(300);
//rotating the 2nd rectangle.
rect2.getTransforms().add(rotate);
Group root = new Group();
root.getChildren().addAll(rect1,rect2);
Scene scene = new Scene(root,500,420);
primaryStage.setScene(scene);
primaryStage.setTitle("Rotation Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}