return CGAlgorithmsDD.orientationIndex(p1, p2, q);
public boolean isParallel(Vector2D v) { return 0.0 == CGAlgorithmsDD.signOfDet2x2(x, y, v.x, v.y); }
private void checkDD(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2, Coordinate intPt) { Coordinate intPtDD = CGAlgorithmsDD.intersection(p1, p2, q1, q2); boolean isIn = isInSegmentEnvelopes(intPtDD); System.out.println( "DD in env = " + isIn + " --------------------- " + intPtDD); if (intPt.distance(intPtDD) > 0.0001) { System.out.println("Distance = " + intPt.distance(intPtDD)); } }
/** * Returns the index of the direction of the point <code>q</code> relative to * a vector specified by <code>p1-p2</code>. * * @param p1 the origin point of the vector * @param p2 the final point of the vector * @param q the point to compute the direction to * * @return 1 if q is counter-clockwise (left) from p1-p2 * @return -1 if q is clockwise (right) from p1-p2 * @return 0 if q is collinear with p1-p2 */ public static int orientationIndex(Coordinate p1, Coordinate p2, Coordinate q) { // fast filter for orientation index // avoids use of slow extended-precision arithmetic in many cases int index = orientationIndexFilter(p1, p2, q); if (index <= 1) return index; // normalize coordinates DD dx1 = DD.valueOf(p2.x).selfAdd(-p1.x); DD dy1 = DD.valueOf(p2.y).selfAdd(-p1.y); DD dx2 = DD.valueOf(q.x).selfAdd(-p2.x); DD dy2 = DD.valueOf(q.y).selfAdd(-p2.y); // sign of determinant - unrolled for performance return dx1.selfMultiply(dy2).selfSubtract(dy1.selfMultiply(dx2)).signum(); }
public static Geometry segmentIntersectionDD(Geometry g1, Geometry g2) { Coordinate[] pt1 = g1.getCoordinates(); Coordinate[] pt2 = g2.getCoordinates(); // first check if there actually is an intersection RobustLineIntersector ri = new RobustLineIntersector(); ri.computeIntersection(pt1[0], pt1[1], pt2[0], pt2[1]); if (! ri.hasIntersection()) { // no intersection => return empty point return g1.getFactory().createPoint((Coordinate) null); } Coordinate intPt = CGAlgorithmsDD.intersection(pt1[0], pt1[1], pt2[0], pt2[1]); return g1.getFactory().createPoint(intPt); } }
return CGAlgorithmsDD.orientationIndex(p1, p2, q);
private void checkSignOfDet2x2(double x1, double y1, double x2, double y2, int sign) { assertEquals(sign, CGAlgorithmsDD.signOfDet2x2(x1, y1, x2, y2)); } }
public static boolean isAllOrientationsEqualDD(Coordinate[] pts) { int orient0 = CGAlgorithmsDD.orientationIndex(pts[0], pts[1], pts[2]); int orient1 = CGAlgorithmsDD.orientationIndex(pts[1], pts[2], pts[0]); int orient2 = CGAlgorithmsDD.orientationIndex(pts[2], pts[0], pts[1]); return orient0 == orient1 && orient0 == orient2; }