/** * Tests whether a triangular ring would be eroded completely by the given * buffer distance. * This is a precise test. It uses the fact that the inner buffer of a * triangle converges on the inCentre of the triangle (the point * equidistant from all sides). If the buffer distance is greater than the * distance of the inCentre from a side, the triangle will be eroded completely. * * This test is important, since it removes a problematic case where * the buffer distance is slightly larger than the inCentre distance. * In this case the triangle buffer curve "inverts" with incorrect topology, * producing an incorrect hole in the buffer. * * @param triangleCoord * @param bufferDistance * @return */ private boolean isTriangleErodedCompletely( Coordinate[] triangleCoord, double bufferDistance) { Triangle tri = new Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]); Coordinate inCentre = tri.inCentre(); double distToCentre = CGAlgorithms.distancePointLine(inCentre, tri.p0, tri.p1); return distToCentre < Math.abs(bufferDistance); }
/** * 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); }
/** * Computes the Z-value (elevation) of an XY point on a three-dimensional * plane defined by this triangle (whose vertices must have Z-values). This * triangle must not be degenerate (in other words, the triangle must enclose * a non-zero area), and must not be parallel to the Z-axis. * <p> * This method can be used to interpolate the Z-value of a point inside this * triangle (for example, of a TIN facet with elevations on the vertices). * * @param p * the point to compute the Z-value of * @return the computed Z-value (elevation) of the point */ public double interpolateZ(Coordinate p) { if (p == null) throw new IllegalArgumentException("Supplied point is null."); return interpolateZ(p, this.p0, this.p1, this.p2); }
Vector3D vector = new Vector3D(normal.getX(), normal.getY(), 0).normalize(); Coordinate inCenter = triangle.centroid(); inCenter.setOrdinate(2, Triangle.interpolateZ(inCenter, triangle.p0, triangle.p1, triangle.p2)); if(intersection != null && distInters < nearestIntersection) { pointIntersection = new Coordinate(intersection.x, intersection.y, Triangle.interpolateZ(intersection, triangle.p0, triangle.p1, triangle.p2)); nearestIntersection = distInters;
/** * A factory to create a DTriangle from a Geometry * * @param geom * @return * @throws IllegalArgumentException * If there are not exactly 3 coordinates in geom. */ public static Triangle createTriangle(Geometry geom) throws IllegalArgumentException { Coordinate[] coordinates = geom.getCoordinates(); if (coordinates.length != 4) { throw new IllegalArgumentException("The geometry must be a triangle"); } return new Triangle(coordinates[0],coordinates[1],coordinates[2]); }
/** * Computes the 2D area of this triangle. The area value is always * non-negative. * * @return the area of this triangle * * @see #signedArea() */ public double area() { return area(this.p0, this.p1, this.p2); }
/** * Computes the centroid (centre of mass) of this triangle. This is also the * point at which the triangle's three medians intersect (a triangle median is * the segment from a vertex of the triangle to the midpoint of the opposite * side). The centroid divides each median in a ratio of 2:1. * <p> * The centroid always lies within the triangle. * * @return the centroid of this triangle */ public Coordinate centroid() { return centroid(this.p0, this.p1, this.p2); }
/** * Computes the 3D area of this triangle. The value computed is alway * non-negative. * * @return the 3D area of this triangle */ public double area3D() { return area3D(this.p0, this.p1, this.p2); }
/** * Computes the incentre of this triangle. The <i>incentre</i> of a triangle * is the point which is equidistant from the sides of the triangle. It is * also the point at which the bisectors of the triangle's angles meet. It is * the centre of the triangle's <i>incircle</i>, which is the unique circle * that is tangent to each of the triangle's three sides. * * @return the point which is the inCentre of this triangle */ public Coordinate inCentre() { return inCentre(p0, p1, p2); }
/** * Tests whether this triangle is acute. A triangle is acute iff all interior * angles are acute. This is a strict test - right triangles will return * <tt>false</tt> A triangle which is not acute is either right or obtuse. * <p> * Note: this implementation is not robust for angles very close to 90 * degrees. * * @return true if this triangle is acute */ public boolean isAcute() { return isAcute(this.p0, this.p1, this.p2); }
Vector3D vector = new Vector3D(normal.getX(), normal.getY(), 0).normalize(); Coordinate inCenter = triangle.centroid(); inCenter.setOrdinate(2, Triangle.interpolateZ(inCenter, triangle.p0, triangle.p1, triangle.p2)); if(intersection != null && distInters < nearestIntersection) { pointIntersection = new Coordinate(intersection.x, intersection.y, Triangle.interpolateZ(intersection, triangle.p0, triangle.p1, triangle.p2)); nearestIntersection = distInters;
/** * A factory to create a DTriangle from a Geometry * * @param geom * @return * @throws DelaunayError * If the triangle can't be generated * @throws IllegalArgumentException * If there are not exactly 3 coordinates in geom. */ public static Triangle createTriangle(Geometry geom) throws IllegalArgumentException { Coordinate[] coordinates = geom.getCoordinates(); if (coordinates.length != 4) { throw new IllegalArgumentException("The geometry must be a triangle"); } return new Triangle(coordinates[0],coordinates[1],coordinates[2]); }
/** * Computes the 2D area of this triangle. The area value is always * non-negative. * * @return the area of this triangle * * @see #signedArea() */ public double area() { return area(this.p0, this.p1, this.p2); }
/** * Computes the centroid (centre of mass) of this triangle. This is also the * point at which the triangle's three medians intersect (a triangle median is * the segment from a vertex of the triangle to the midpoint of the opposite * side). The centroid divides each median in a ratio of 2:1. * <p> * The centroid always lies within the triangle. * * @return the centroid of this triangle */ public Coordinate centroid() { return centroid(this.p0, this.p1, this.p2); }
/** * Computes the 3D area of this triangle. The value computed is alway * non-negative. * * @return the 3D area of this triangle */ public double area3D() { return area3D(this.p0, this.p1, this.p2); }
/** * Computes the incentre of this triangle. The <i>incentre</i> of a triangle * is the point which is equidistant from the sides of the triangle. It is * also the point at which the bisectors of the triangle's angles meet. It is * the centre of the triangle's <i>incircle</i>, which is the unique circle * that is tangent to each of the triangle's three sides. * * @return the point which is the inCentre of this triangle */ public Coordinate inCentre() { return inCentre(p0, p1, p2); }
/** * Tests whether this triangle is acute. A triangle is acute iff all interior * angles are acute. This is a strict test - right triangles will return * <tt>false</tt> A triangle which is not acute is either right or obtuse. * <p> * Note: this implementation is not robust for angles very close to 90 * degrees. * * @return true if this triangle is acute */ public boolean isAcute() { return isAcute(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; } }