signedAreaStatic static method

double signedAreaStatic(
  1. Coordinate a,
  2. Coordinate b,
  3. Coordinate c
)

Computes the signed 2D area of a triangle. The area value is positive if the triangle is oriented CW, and negative if it is oriented CCW.

The signed area value can be used to determine point orientation, but the implementation in this method is susceptible to round-off errors. Use {@link Orientation#index(Coordinate, Coordinate, Coordinate)} for robust orientation calculation.

@param a a vertex of the triangle @param b a vertex of the triangle @param c a vertex of the triangle @return the signed 2D area of the triangle

@see Orientation#index(Coordinate, Coordinate, Coordinate)

Implementation

static double signedAreaStatic(Coordinate a, Coordinate b, Coordinate c) {
  /**
   * Uses the formula 1/2 * | u x v | where u,v are the side vectors of the
   * triangle x is the vector cross-product For 2D vectors, this formula
   * simplifies to the expression below
   */
  return ((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2;
}