double ang0 = Angle.angle(basePt, seg0.p0); double ang1 = Angle.angle(basePt, seg1.p1); double angDiff = Angle.angleBetweenOriented(seg0.p0, basePt, seg1.p1); double midAng = Angle.normalize(ang0 + angDiffHalf); double mitreMidAng = Angle.normalize(midAng + Math.PI);
private static Coordinate pointWithMinAngleWithSegment(Coordinate[] pts, Coordinate P, Coordinate Q) { double minAng = Double.MAX_VALUE; Coordinate minAngPt = null; for (int i = 0; i < pts.length; i++) { Coordinate p = pts[i]; if (p == P) continue; if (p == Q) continue; double ang = Angle.angleBetween(P, p, Q); if (ang < minAng) { minAng = ang; minAngPt = p; } } return minAngPt; } }
/** * Returns the unoriented smallest angle between two vectors. * The computed angle will be in the range [0, Pi). * * @param tip1 the tip of one vector * @param tail the tail of each vector * @param tip2 the tip of the other vector * @return the angle between tail-tip1 and tail-tip2 */ public static double angleBetween(Coordinate tip1, Coordinate tail, Coordinate tip2) { double a1 = angle(tail, tip1); double a2 = angle(tail, tip2); return diff(a1, a2); }
/** * Returns the oriented smallest angle between two vectors. * The computed angle will be in the range (-Pi, Pi]. * A positive result corresponds to a counterclockwise * (CCW) rotation * from v1 to v2; * a negative result corresponds to a clockwise (CW) rotation; * a zero result corresponds to no rotation. * * @param tip1 the tip of v1 * @param tail the tail of each vector * @param tip2 the tip of v2 * @return the angle between v1 and v2, relative to v1 */ public static double angleBetweenOriented(Coordinate tip1, Coordinate tail, Coordinate tip2) { double a1 = angle(tail, tip1); double a2 = angle(tail, tip2); double angDel = a2 - a1; // normalize, maintaining orientation if (angDel <= -Math.PI) return angDel + PI_TIMES_2; if (angDel > Math.PI) return angDel - PI_TIMES_2; return angDel; }
Coordinate rotPt = new Coordinate(dest1.x - dest0.x, dest1.y - dest0.y); double ang = Angle.angleBetweenOriented(src1, src0, rotPt);
public double angle(Vector2D v) { return Angle.diff(v.angle(), angle()); }
/** * Tests whether a 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. * * @param a * a vertex of the triangle * @param b * a vertex of the triangle * @param c * a vertex of the triangle * @return true if the triangle is acute */ public static boolean isAcute(Coordinate a, Coordinate b, Coordinate c) { if (!Angle.isAcute(a, b, c)) return false; if (!Angle.isAcute(b, c, a)) return false; if (!Angle.isAcute(c, a, b)) return false; return true; }
private String getFormatedAngle(Coordinate c1, Coordinate c2, Coordinate c3) { return DECIMAL_FORMAT.format(Angle.toDegrees(getAngle(c1, c2, c3))) + "º"; }
/** * Computes the interior angle between two segments of a ring. The ring is * assumed to be oriented in a clockwise direction. The computed angle will be * in the range [0, 2Pi] * * @param p0 * a point of the ring * @param p1 * the next point of the ring * @param p2 * the next point of the ring * @return the interior angle based at <code>p1</code> */ public static double interiorAngle(Coordinate p0, Coordinate p1, Coordinate p2) { double anglePrev = Angle.angle(p1, p0); double angleNext = Angle.angle(p1, p2); return Math.abs(angleNext - anglePrev); }
double ang = Angle.angleBetweenOriented(src1, src0, rotPt);
public double angle(Vector2D v) { return Angle.diff(v.angle(), angle()); }
/** * Tests whether a 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. * * @param a * a vertex of the triangle * @param b * a vertex of the triangle * @param c * a vertex of the triangle * @return true if the triangle is acute */ public static boolean isAcute(Coordinate a, Coordinate b, Coordinate c) { if (!Angle.isAcute(a, b, c)) return false; if (!Angle.isAcute(b, c, a)) return false; if (!Angle.isAcute(c, a, b)) return false; return true; }
double ang0 = Angle.angle(basePt, seg0.p0); double ang1 = Angle.angle(basePt, seg1.p1); double angDiff = Angle.angleBetweenOriented(seg0.p0, basePt, seg1.p1); double midAng = Angle.normalize(ang0 + angDiffHalf); double mitreMidAng = Angle.normalize(midAng + Math.PI);
/** * Returns the oriented smallest angle between two vectors. * The computed angle will be in the range (-Pi, Pi]. * A positive result corresponds to a counterclockwise * (CCW) rotation * from v1 to v2; * a negative result corresponds to a clockwise (CW) rotation; * a zero result corresponds to no rotation. * * @param tip1 the tip of v1 * @param tail the tail of each vector * @param tip2 the tip of v2 * @return the angle between v1 and v2, relative to v1 */ public static double angleBetweenOriented(Coordinate tip1, Coordinate tail, Coordinate tip2) { double a1 = angle(tail, tip1); double a2 = angle(tail, tip2); double angDel = a2 - a1; // normalize, maintaining orientation if (angDel <= -Math.PI) return angDel + PI_TIMES_2; if (angDel > Math.PI) return angDel - PI_TIMES_2; return angDel; }
/** * Returns the unoriented smallest angle between two vectors. * The computed angle will be in the range [0, Pi). * * @param tip1 the tip of one vector * @param tail the tail of each vector * @param tip2 the tip of the other vector * @return the angle between tail-tip1 and tail-tip2 */ public static double angleBetween(Coordinate tip1, Coordinate tail, Coordinate tip2) { double a1 = angle(tail, tip1); double a2 = angle(tail, tip2); return diff(a1, a2); }
Coordinate rotPt = new Coordinate(dest1.x - dest0.x, dest1.y - dest0.y); double ang = Angle.angleBetweenOriented(src1, src0, rotPt);
private static Coordinate pointWithMinAngleWithSegment(Coordinate[] pts, Coordinate P, Coordinate Q) { double minAng = Double.MAX_VALUE; Coordinate minAngPt = null; for (int i = 0; i < pts.length; i++) { Coordinate p = pts[i]; if (p == P) continue; if (p == Q) continue; double ang = Angle.angleBetween(P, p, Q); if (ang < minAng) { minAng = ang; minAngPt = p; } } return minAngPt; } }
/** * Computes the interior angle between two segments of a ring. The ring is * assumed to be oriented in a clockwise direction. The computed angle will be * in the range [0, 2Pi] * * @param p0 * a point of the ring * @param p1 * the next point of the ring * @param p2 * the next point of the ring * @return the interior angle based at <code>p1</code> */ public static double interiorAngle(Coordinate p0, Coordinate p1, Coordinate p2) { double anglePrev = Angle.angle(p1, p0); double angleNext = Angle.angle(p1, p2); return Math.abs(angleNext - anglePrev); }