下面列出了javafx.scene.shape.Line#getStartY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static boolean inLine(Line line, int x, int y) {
double d = (x - line.getStartX()) * (line.getStartY() - line.getEndY())
- ((line.getStartX() - line.getEndX()) * (y - line.getStartY()));
return Math.abs(d) < 0.0001
&& (x >= Math.min(line.getStartX(), line.getEndX())
&& x <= Math.max(line.getStartX(), line.getEndX()))
&& (y >= Math.min(line.getStartY(), line.getEndY()))
&& (y <= Math.max(line.getStartY(), line.getEndY()));
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a pane
Pane pane = new Pane();
// Create two circles
Circle circle1 = new Circle(Math.random() * 201, Math.random() * 201, 15);
Circle circle2 = new Circle(Math.random() * 201, Math.random() * 201, 15);
// Create a line
Line line = new Line(circle1.getCenterX(), circle1.getCenterY(),
circle2.getCenterX(), circle2.getCenterY());
// Calculate distane between the two centers of the circles
double distance = Math.sqrt(Math.pow(line.getEndX() - line.getStartX(), 2)
+ Math.pow(line.getEndY() - line.getStartY(), 2));
// Create a text
double x = (line.getStartX() + line.getEndX()) / 2;
double y = (line.getStartY() + line.getEndY()) / 2;
Text text = new Text(x, y, String.valueOf(distance));
// Add nodes to pane
pane.getChildren().addAll(circle1, circle2, line, text);
// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("Exercise_14_21"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* Converts the given JavaFX {@link Line} to a
* {@link org.eclipse.gef.geometry.planar.Line}.
*
* @param line
* The JavaFX {@link Line} to convert.
* @return The newly created {@link org.eclipse.gef.geometry.planar.Line}
* that describes the given {@link Line}.
*/
public static org.eclipse.gef.geometry.planar.Line toLine(Line line) {
return new org.eclipse.gef.geometry.planar.Line(line.getStartX(),
line.getStartY(), line.getEndX(), line.getEndY());
}