Java Code Examples for javafx.scene.shape.Line#getEndY()

The following examples show how to use javafx.scene.shape.Line#getEndY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example 2
Source File: Exercise_14_21.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@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
}
 
Example 3
Source File: Exercise_14_18.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create two panes
	Pane pane1 = new Pane();
	pane1.setRotate(180);
	pane1.setPadding(new Insets(72, 0, 0, 75));
	Pane pane2 = new Pane();

	// Create a polyline
	Polyline polyline1 = new Polyline();
	pane1.getChildren().add(polyline1);             
	ObservableList<Double> list = polyline1.getPoints();
	double scaleFactor = 0.0125;                       
	for (int x = -100; x <= 100; x++) {                
		list.add(x + 200.0);                            
		list.add(scaleFactor * x * x);                  
	}  

	// Create two lines
	Line lineX = new Line(10, 200, 350, 200);                                                
	//pane.getChildren().addAll(stackPane, lineX);

	Line lineY = new Line(lineX.getEndX() / 2, 250, lineX.getEndX() / 2, 30);                                                
	pane2.getChildren().addAll(pane1, lineX, lineY);

	// Create two polylines
	Polyline polyline2 = new Polyline();
	pane2.getChildren().add(polyline2);
	ObservableList<Double> list2 = polyline2.getPoints();
	list2.addAll(lineY.getEndX() - 10, lineY.getEndY() + 20, 
		lineY.getEndX(), lineY.getEndY(), lineY.getEndX() + 10, 
		lineY. getEndY() + 20);

	Polyline polyline3 = new Polyline();
	pane2.getChildren().add(polyline3);
	ObservableList<Double> list3 = polyline3.getPoints();
	list3.addAll(lineX.getEndX() - 20, lineX.getEndY() - 10, 
		lineX.getEndX(), lineX.getEndY(), lineX.getEndX() - 20, 
		lineX. getEndY() + 10);

	// Create two text objects
	Text textX = new Text(lineX.getEndX() - 10, lineX.getEndY() - 20, "X");
	Text textY = new Text(lineY.getEndX() + 20, lineY.getEndY() + 10, "Y");
	pane2.getChildren().addAll(textX, textY);

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane2);
	primaryStage.setTitle("Exercise_14_18"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 4
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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());
}