/** * Computes the sign of the determinant of the 2x2 matrix * with the given entries. * * @return -1 if the determinant is negative, * @return 1 if the determinant is positive, * @return 0 if the determinant is 0. */ public static int signOfDet2x2(DD x1, DD y1, DD x2, DD y2) { DD det = x1.multiply(y2).selfSubtract(y1.multiply(x2)); return det.signum(); }
/** * Computes the sign of the determinant of the 2x2 matrix * with the given entries. * * @return -1 if the determinant is negative, * @return 1 if the determinant is positive, * @return 0 if the determinant is 0. */ public static int signOfDet2x2(double dx1, double dy1, double dx2, double dy2) { DD x1 = DD.valueOf(dx1); DD y1 = DD.valueOf(dy1); DD x2 = DD.valueOf(dx2); DD y2 = DD.valueOf(dy2); DD det = x1.multiply(y2).selfSubtract(y1.multiply(x2)); return det.signum(); }
/** * 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(); }