Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a signedAngle() function to the PVector class #773

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/src/processing/core/PVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down