Java Code Examples for javafx.geometry.Point2D#midpoint()
The following examples show how to use
javafx.geometry.Point2D#midpoint() .
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: Exercise_18_19.java From Intro-to-Java-Programming with MIT License | 6 votes |
private void displayTriangles(int order, Point2D p1, Point2D p2, Point2D p3) { if (order == 0) { // Draw a triangle to connect three points Polygon triangle = new Polygon(); triangle.getPoints().addAll(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); triangle.setStroke(Color.BLACK); triangle.setFill(Color.WHITE); this.getChildren().add(triangle); } else { //Get the midpoint on each edge in the triangle Point2D p12= p1.midpoint(p2); Point2D p23= p2.midpoint(p3); Point2D p31= p3.midpoint(p1); // Recursively display three triangles displayTriangles(order - 1, p1, p12, p31); displayTriangles(order - 1, p12, p2, p23); displayTriangles(order - 1, p31, p23, p3); } }
Example 2
Source File: Exercise_18_36.java From Intro-to-Java-Programming with MIT License | 6 votes |
private void displayTriangles(int order, Point2D p1, Point2D p2, Point2D p3) { if (order == 0) { // Draw a triangle to connect three points Polygon triangle = new Polygon(); triangle.getPoints().addAll(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); triangle.setStroke(Color.BLACK); triangle.setFill(Color.BLACK); this.getChildren().add(triangle); } else { //Get the midpoint on each edge in the triangle Point2D p12= p1.midpoint(p2); Point2D p23= p2.midpoint(p3); Point2D p31= p3.midpoint(p1); // Recursively display three triangles displayTriangles(order - 1, p1, p12, p31); displayTriangles(order - 1, p12, p2, p23); displayTriangles(order - 1, p31, p23, p3); } }