angleBetweenOriented static method
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
Implementation
static double angleBetweenOriented(
Coordinate tip1, Coordinate tail, Coordinate tip2) {
double a1 = angle2C(tail, tip1);
double a2 = angle2C(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;
}