/** * Tests if a point is inside the circle defined by * the triangle with vertices a, b, c (oriented counter-clockwise). * This method uses more robust computation. * * @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 isInCircleRobust( Coordinate a, Coordinate b, Coordinate c, Coordinate p) { //checkRobustInCircle(a, b, c, p); // return isInCircleNonRobust(a, b, c, p); return isInCircleNormalized(a, b, c, p); }
/** * Tests if the vertex is inside the circle defined by * the triangle with vertices a, b, c (oriented counter-clockwise). * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @return true if this vertex is in the circumcircle of (a,b,c) */ public boolean isInCircle(Vertex a, Vertex b, Vertex c) { return TrianglePredicate.isInCircleRobust(a.p, b.p, c.p, this.p); // non-robust - best to not use //return TrianglePredicate.isInCircle(a.p, b.p, c.p, this.p); }
/** * Tests if a point is inside the circle defined by * the triangle with vertices a, b, c (oriented counter-clockwise). * This test uses simple * double-precision arithmetic, and thus may not be robust. * * @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 isInCircleNonRobust( Coordinate a, Coordinate b, Coordinate c, Coordinate p) { boolean isInCircle = (a.x * a.x + a.y * a.y) * triArea(b, c, p) - (b.x * b.x + b.y * b.y) * triArea(a, c, p) + (c.x * c.x + c.y * c.y) * triArea(a, b, p) - (p.x * p.x + p.y * p.y) * triArea(a, b, c) > 0; return isInCircle; }
Coordinate p) boolean nonRobustInCircle = isInCircleNonRobust(a, b, c, p); boolean isInCircleDD = TrianglePredicate.isInCircleDDSlow(a, b, c, p); boolean isInCircleCC = TrianglePredicate.isInCircleCC(a, b, c, p);
public static boolean isInCircleDDFast( Coordinate a, Coordinate b, Coordinate c, Coordinate p) { DD aTerm = (DD.sqr(a.x).selfAdd(DD.sqr(a.y))) .selfMultiply(triAreaDDFast(b, c, p)); DD bTerm = (DD.sqr(b.x).selfAdd(DD.sqr(b.y))) .selfMultiply(triAreaDDFast(a, c, p)); DD cTerm = (DD.sqr(c.x).selfAdd(DD.sqr(c.y))) .selfMultiply(triAreaDDFast(a, b, p)); DD pTerm = (DD.sqr(p.x).selfAdd(DD.sqr(p.y))) .selfMultiply(triAreaDDFast(a, b, c)); DD sum = aTerm.selfSubtract(bTerm).selfAdd(cTerm).selfSubtract(pTerm); boolean isInCircle = sum.doubleValue() > 0; return isInCircle; }
.multiply(triAreaDDSlow(bx, by, cx, cy, px, py)); DD bTerm = (bx.multiply(bx).add(by.multiply(by))) .multiply(triAreaDDSlow(ax, ay, cx, cy, px, py)); DD cTerm = (cx.multiply(cx).add(cy.multiply(cy))) .multiply(triAreaDDSlow(ax, ay, bx, by, px, py)); DD pTerm = (px.multiply(px).add(py.multiply(py))) .multiply(triAreaDDSlow(ax, ay, bx, by, cx, cy));
Coordinate p) boolean nonRobustInCircle = isInCircleNonRobust(a, b, c, p); boolean isInCircleDD = TrianglePredicate.isInCircleDDSlow(a, b, c, p); boolean isInCircleCC = TrianglePredicate.isInCircleCC(a, b, c, p);
public static boolean isInCircleDDFast( Coordinate a, Coordinate b, Coordinate c, Coordinate p) { DD aTerm = (DD.sqr(a.x).selfAdd(DD.sqr(a.y))) .selfMultiply(triAreaDDFast(b, c, p)); DD bTerm = (DD.sqr(b.x).selfAdd(DD.sqr(b.y))) .selfMultiply(triAreaDDFast(a, c, p)); DD cTerm = (DD.sqr(c.x).selfAdd(DD.sqr(c.y))) .selfMultiply(triAreaDDFast(a, b, p)); DD pTerm = (DD.sqr(p.x).selfAdd(DD.sqr(p.y))) .selfMultiply(triAreaDDFast(a, b, c)); DD sum = aTerm.selfSubtract(bTerm).selfAdd(cTerm).selfSubtract(pTerm); boolean isInCircle = sum.doubleValue() > 0; return isInCircle; }
.multiply(triAreaDDSlow(bx, by, cx, cy, px, py)); DD bTerm = (bx.multiply(bx).add(by.multiply(by))) .multiply(triAreaDDSlow(ax, ay, cx, cy, px, py)); DD cTerm = (cx.multiply(cx).add(cy.multiply(cy))) .multiply(triAreaDDSlow(ax, ay, bx, by, px, py)); DD pTerm = (px.multiply(px).add(py.multiply(py))) .multiply(triAreaDDSlow(ax, ay, bx, by, cx, cy));
/** * Tests if the vertex is inside the circle defined by * the triangle with vertices a, b, c (oriented counter-clockwise). * * @param a a vertex of the triangle * @param b a vertex of the triangle * @param c a vertex of the triangle * @return true if this vertex is in the circumcircle of (a,b,c) */ public boolean isInCircle(Vertex a, Vertex b, Vertex c) { return TrianglePredicate.isInCircleRobust(a.p, b.p, c.p, this.p); // non-robust - best to not use //return TrianglePredicate.isInCircle(a.p, b.p, c.p, this.p); }
/** * Tests if a point is inside the circle defined by * the triangle with vertices a, b, c (oriented counter-clockwise). * This method uses more robust computation. * * @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 isInCircleRobust( Coordinate a, Coordinate b, Coordinate c, Coordinate p) { //checkRobustInCircle(a, b, c, p); // return isInCircleNonRobust(a, b, c, p); return isInCircleNormalized(a, b, c, p); }
/** * Tests if a point is inside the circle defined by * the triangle with vertices a, b, c (oriented counter-clockwise). * This test uses simple * double-precision arithmetic, and thus may not be robust. * * @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 isInCircleNonRobust( Coordinate a, Coordinate b, Coordinate c, Coordinate p) { boolean isInCircle = (a.x * a.x + a.y * a.y) * triArea(b, c, p) - (b.x * b.x + b.y * b.y) * triArea(a, c, p) + (c.x * c.x + c.y * c.y) * triArea(a, b, p) - (p.x * p.x + p.y * p.y) * triArea(a, b, c) > 0; return isInCircle; }