diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java index a2bdd4718..2be15cd7b 100644 --- a/core/src/processing/core/PVector.java +++ b/core/src/processing/core/PVector.java @@ -991,6 +991,24 @@ static public float angleBetween(PVector v1, PVector v2) { return (float) Math.acos(amt); } + /** + * + * Get the signed (directed) angle between two (2D) vectors. The angle it returns + * will be between -PI and +PI with clockwise being negative and counterclockwise + * being positive. + * + * + * @webref pvector:method + * @usage web_application + * @webBrief Get signed angle between two vectors (2D only) + * @param from the vector from which the angle is measured + * @param to the vector to which the angle is measured + * @return the angle in radians + */ + static public float signedAngle(PVector from, PVector to) { + return (float) (Math.atan2(to.y, to.x) - Math.atan2(from.y, from.x)); + } + @Override public String toString() {