isObtuse static method

bool isObtuse(
  1. Coordinate p0,
  2. Coordinate p1,
  3. Coordinate p2
)

Tests whether the angle between p0-p1-p2 is obtuse. An angle is obtuse if it is greater than 90 degrees.

Note: this implementation is not precise (deterministic) for angles very close to 90 degrees.

@param p0 an endpoint of the angle @param p1 the base of the angle @param p2 the other endpoint of the angle @return true if the angle is obtuse

Implementation

static bool isObtuse(Coordinate p0, Coordinate p1, Coordinate p2) {
  // relies on fact that A dot B is negative iff A ang B is obtuse
  double dx0 = p0.x - p1.x;
  double dy0 = p0.y - p1.y;
  double dx1 = p2.x - p1.x;
  double dy1 = p2.y - p1.y;
  double dotprod = dx0 * dx1 + dy0 * dy1;
  return dotprod < 0;
}