/** * Computes the circumcentre of this triangle. The circumcentre is the centre * of the circumcircle, the smallest circle which encloses the triangle. It is * also the common intersection point of the perpendicular bisectors of the * sides of the triangle, and is the only point which has equal distance to * all three vertices of the triangle. * <p> * The circumcentre does not necessarily lie within the triangle. * <p> * This method uses an algorithm due to J.R.Shewchuk which uses normalization * to the origin to improve the accuracy of computation. (See <i>Lecture Notes * on Geometric Robustness</i>, Jonathan Richard Shewchuk, 1999). * * @return the circumcentre of this triangle */ public Coordinate circumcentre() { return circumcentre(this.p0, this.p1, this.p2); }
private void computeCentre() { switch (extremalPts.length) { case 0: centre = null; break; case 1: centre = extremalPts[0]; break; case 2: centre = new Coordinate( (extremalPts[0].x + extremalPts[1].x) / 2.0, (extremalPts[0].y + extremalPts[1].y) / 2.0 ); break; case 3: centre = Triangle.circumcentre(extremalPts[0], extremalPts[1], extremalPts[2]); break; } }
/** * Computes the inCircle test using distance from the circumcentre. * Uses standard double-precision arithmetic. * <p> * In general this doesn't * appear to be any more robust than the standard calculation. However, there * is at least one case where the test point is far enough from the * circumcircle that this test gives the correct answer. * <pre> * LINESTRING * (1507029.9878 518325.7547, 1507022.1120341457 518332.8225183258, * 1507029.9833 518325.7458, 1507029.9896965567 518325.744909031) * </pre> * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @param p the point to test * @return true if this point is inside the circle defined by the points a, b, c */ public static boolean isInCircleCC(Coordinate a, Coordinate b, Coordinate c, Coordinate p) { Coordinate cc = Triangle.circumcentre(a, b, c); double ccRadius = a.distance(cc); double pRadiusDiff = p.distance(cc) - ccRadius; return pRadiusDiff <= 0; }
boolean isInCircleCC = TrianglePredicate.isInCircleCC(a, b, c, p); Coordinate circumCentre = Triangle.circumcentre(a, b, c); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) - a.distance(circumCentre))
public void visit(QuadEdge[] triEdges) { Coordinate a = triEdges[0].orig().getCoordinate(); Coordinate b = triEdges[1].orig().getCoordinate(); Coordinate c = triEdges[2].orig().getCoordinate(); // TODO: choose the most accurate circumcentre based on the edges Coordinate cc = Triangle.circumcentre(a, b, c); Vertex ccVertex = new Vertex(cc); // save the circumcentre as the origin for the dual edges originating in this triangle for (int i = 0; i < 3; i++) { triEdges[i].rot().setOrig(ccVertex); } } }
/** * Computes the circumcentre of this triangle. The circumcentre is the centre * of the circumcircle, the smallest circle which encloses the triangle. It is * also the common intersection point of the perpendicular bisectors of the * sides of the triangle, and is the only point which has equal distance to * all three vertices of the triangle. * <p> * The circumcentre does not necessarily lie within the triangle. * <p> * This method uses an algorithm due to J.R.Shewchuk which uses normalization * to the origin to improve the accuracy of computation. (See <i>Lecture Notes * on Geometric Robustness</i>, Jonathan Richard Shewchuk, 1999). * * @return the circumcentre of this triangle */ public Coordinate circumcentre() { return circumcentre(this.p0, this.p1, this.p2); }
private void computeCentre() { switch (extremalPts.length) { case 0: centre = null; break; case 1: centre = extremalPts[0]; break; case 2: centre = new Coordinate( (extremalPts[0].x + extremalPts[1].x) / 2.0, (extremalPts[0].y + extremalPts[1].y) / 2.0 ); break; case 3: centre = Triangle.circumcentre(extremalPts[0], extremalPts[1], extremalPts[2]); break; } }
private Coordinate getCircumcenter(int idgeom, Coordinate[] triangleCircumcenter) { Coordinate circumcenter = triangleCircumcenter[idgeom]; if(circumcenter == null) { circumcenter = getTriangle(idgeom).circumcentre(); if(hasZ) { circumcenter = new Coordinate(circumcenter.x, circumcenter.y, fetchZ(circumcenter, idgeom)); } triangleCircumcenter[idgeom] = circumcenter; } return circumcenter; }
private Coordinate getCircumcenter(int idgeom, Coordinate[] triangleCircumcenter) { Coordinate circumcenter = triangleCircumcenter[idgeom]; if(circumcenter == null) { circumcenter = getTriangle(idgeom).circumcentre(); if(hasZ) { circumcenter = new Coordinate(circumcenter.x, circumcenter.y, fetchZ(circumcenter, idgeom)); } triangleCircumcenter[idgeom] = circumcenter; } return circumcenter; }
/** * Computes the inCircle test using distance from the circumcentre. * Uses standard double-precision arithmetic. * <p> * In general this doesn't * appear to be any more robust than the standard calculation. However, there * is at least one case where the test point is far enough from the * circumcircle that this test gives the correct answer. * <pre> * LINESTRING * (1507029.9878 518325.7547, 1507022.1120341457 518332.8225183258, * 1507029.9833 518325.7458, 1507029.9896965567 518325.744909031) * </pre> * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @param p the point to test * @return true if this point is inside the circle defined by the points a, b, c */ public static boolean isInCircleCC(Coordinate a, Coordinate b, Coordinate c, Coordinate p) { Coordinate cc = Triangle.circumcentre(a, b, c); double ccRadius = a.distance(cc); double pRadiusDiff = p.distance(cc) - ccRadius; return pRadiusDiff <= 0; }
@Override public void visit(QuadEdge[] triEdges) { Coordinate a = triEdges[0].orig().getCoordinate(); Coordinate b = triEdges[1].orig().getCoordinate(); Coordinate c = triEdges[2].orig().getCoordinate(); circumCenters.add(Triangle.circumcentre(a, b, c)); } }
@Override public void visit(QuadEdge[] triEdges) { Coordinate a = triEdges[0].orig().getCoordinate(); Coordinate b = triEdges[1].orig().getCoordinate(); Coordinate c = triEdges[2].orig().getCoordinate(); circumCenters.add(Triangle.circumcentre(a, b, c)); } }
boolean isInCircleCC = TrianglePredicate.isInCircleCC(a, b, c, p); Coordinate circumCentre = Triangle.circumcentre(a, b, c); System.out.println("p radius diff a = " + Math.abs(p.distance(circumCentre) - a.distance(circumCentre))
public void visit(QuadEdge[] triEdges) { Coordinate a = triEdges[0].orig().getCoordinate(); Coordinate b = triEdges[1].orig().getCoordinate(); Coordinate c = triEdges[2].orig().getCoordinate(); // TODO: choose the most accurate circumcentre based on the edges Coordinate cc = Triangle.circumcentre(a, b, c); Vertex ccVertex = new Vertex(cc); // save the circumcentre as the origin for the dual edges originating in this triangle for (int i = 0; i < 3; i++) { triEdges[i].rot().setOrig(ccVertex); } } }