use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.
the class TriPredicate method isInCircleDD.
/**
* Tests if a point is inside the circle defined by the points a, b, c.
* The computation uses {@link DD} arithmetic for robustness.
*
* @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 isInCircleDD(final Point a, final Point b, final Point c, final Point p) {
final DD px = new DD(p.getX());
final DD py = new DD(p.getY());
final DD ax = new DD(a.getX());
final DD ay = new DD(a.getY());
final DD bx = new DD(b.getX());
final DD by = new DD(b.getY());
final DD cx = new DD(c.getX());
final DD cy = new DD(c.getY());
final DD aTerm = ax.multiply(ax).add(ay.multiply(ay)).multiply(triAreaDD(bx, by, cx, cy, px, py));
final DD bTerm = bx.multiply(bx).add(by.multiply(by)).multiply(triAreaDD(ax, ay, cx, cy, px, py));
final DD cTerm = cx.multiply(cx).add(cy.multiply(cy)).multiply(triAreaDD(ax, ay, bx, by, px, py));
final DD pTerm = px.multiply(px).add(py.multiply(py)).multiply(triAreaDD(ax, ay, bx, by, cx, cy));
final DD sum = aTerm.subtract(bTerm).add(cTerm).subtract(pTerm);
final boolean isInCircle = sum.doubleValue() > 0;
return isInCircle;
}
use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.
the class TriPredicate method isInCircleDD3.
public static boolean isInCircleDD3(final Point a, final Point b, final Point c, final Point p) {
final DD adx = DD.valueOf(a.getX()).selfSubtract(p.getX());
final DD ady = DD.valueOf(a.getY()).selfSubtract(p.getY());
final DD bdx = DD.valueOf(b.getX()).selfSubtract(p.getX());
final DD bdy = DD.valueOf(b.getY()).selfSubtract(p.getY());
final DD cdx = DD.valueOf(c.getX()).selfSubtract(p.getX());
final DD cdy = DD.valueOf(c.getY()).selfSubtract(p.getY());
final DD abdet = adx.multiply(bdy).selfSubtract(bdx.multiply(ady));
final DD bcdet = bdx.multiply(cdy).selfSubtract(cdx.multiply(bdy));
final DD cadet = cdx.multiply(ady).selfSubtract(adx.multiply(cdy));
final DD alift = adx.multiply(adx).selfSubtract(ady.multiply(ady));
final DD blift = bdx.multiply(bdx).selfSubtract(bdy.multiply(bdy));
final DD clift = cdx.multiply(cdx).selfSubtract(cdy.multiply(cdy));
final DD sum = alift.selfMultiply(bcdet).selfAdd(blift.selfMultiply(cadet)).selfAdd(clift.selfMultiply(abdet));
final boolean isInCircle = sum.doubleValue() > 0;
return isInCircle;
}
use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.
the class DDIOTest method testStandardNotation.
public void testStandardNotation() {
// standard cases
checkStandardNotation(1.0, "1.0");
checkStandardNotation(0.0, "0.0");
// cases where hi is a power of 10 and lo is negative
checkStandardNotation(DD.valueOf(1e12).subtract(DD.valueOf(1)), "999999999999.0");
checkStandardNotation(DD.valueOf(1e14).subtract(DD.valueOf(1)), "99999999999999.0");
checkStandardNotation(DD.valueOf(1e16).subtract(DD.valueOf(1)), "9999999999999999.0");
final DD num8Dec = DD.valueOf(-379363639).divide(DD.valueOf(100000000));
checkStandardNotation(num8Dec, "-3.79363639");
checkStandardNotation(new DD(-3.79363639, 8.039137357367426E-17), "-3.7936363900000000000000000");
checkStandardNotation(DD.valueOf(34).divide(DD.valueOf(1000)), "0.034");
checkStandardNotation(1.05e3, "1050.0");
checkStandardNotation(0.34, "0.34000000000000002442490654175344");
checkStandardNotation(DD.valueOf(34).divide(DD.valueOf(100)), "0.34");
checkStandardNotation(14, "14.0");
}
use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.
the class DDIOTest method checkParse.
private void checkParse(final String str, final DD expectedVal, final double relErrBound) {
final DD xdd = DD.parse(str);
final double err = xdd.subtract(expectedVal).doubleValue();
final double relErr = err / xdd.doubleValue();
// System.out.println("Parsed= " + xdd + " rel err= " + relErr);
assertTrue(err <= relErrBound);
}
use of com.revolsys.geometry.math.DD in project com.revolsys.open by revolsys.
the class DDIOTest method writeRepeatedSqrt.
/**
* This routine simply tests for robustness of the toString function.
*
* @param xdd
*/
void writeRepeatedSqrt(DD xdd) {
int count = 0;
while (xdd.doubleValue() > 1e-300) {
count++;
final double x = xdd.doubleValue();
final DD xSqrt = xdd.sqrt();
final String s = xSqrt.toString();
// System.out.println(count + ": " + s);
final DD xSqrt2 = DD.parse(s);
final DD xx = xSqrt2.multiply(xSqrt2);
final double err = Math.abs(xx.doubleValue() - x);
// assertTrue(err < 1e-10);
xdd = xSqrt;
// square roots converge on 1 - stop when very close
final DD distFrom1DD = xSqrt.subtract(DD.valueOf(1.0));
final double distFrom1 = distFrom1DD.doubleValue();
if (Math.abs(distFrom1) < 1.0e-40) {
break;
}
}
}
Aggregations