Skip to content

Update docs for setHeading #1015

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 17 additions & 4 deletions core/src/processing/core/PVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -848,13 +848,15 @@ public PVector setMag(PVector target, float len) {

/**
*
* Calculate the angle of rotation for this vector (only 2D vectors)
*
* Calculate the vector's direction, that is, the angle this vector makes
* with the positive X axis (only 2D vectors)
*
*
* @webref pvector:method
* @usage web_application
* @return the angle of rotation
* @return the direction of the vector (angle with positive X axis)
* @webBrief Calculate the angle of rotation for this vector
* @see PVector#setHeading()
*/
public float heading() {
float angle = (float) Math.atan2(y, x);
Expand All @@ -867,7 +869,18 @@ public float heading2D() {
return heading();
}


/**
*
* Sets the angle this vector makes with the positive X axis (only 2D vectors)
* This is equivalent to changing the vector's direction to the given value.
*
* @webref pvector:method
* @usage web_application
* @param angle the direction of the resultant vector
* @return this vector, rotated to have the given direction
* @webBrief Set the direction for this vector
* @see PVector#heading()
*/
public PVector setHeading(float angle) {
float m = mag();
x = (float) (m * Math.cos(angle));
Expand Down
13 changes: 13 additions & 0 deletions java/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ size FUNCTION2 FloatList_size_
sort FUNCTION2 FloatList_sort_
sortReverse FUNCTION2 FloatList_sortReverse_
sub FUNCTION2 FloatList_sub_
toArray FUNCTION2 FloatList_toArray_
floor FUNCTION1 floor_
focused KEYWORD4 focused
frameCount KEYWORD4 frameCount
Expand Down Expand Up @@ -559,6 +560,7 @@ size FUNCTION2 IntList_size_
sort FUNCTION2 IntList_sort_
sortReverse FUNCTION2 IntList_sortReverse_
sub FUNCTION2 IntList_sub_
toArray FUNCTION2 IntList_toArray_
join FUNCTION1 join_
JSONArray KEYWORD5 JSONArray
append FUNCTION2 JSONArray_append_
Expand All @@ -579,6 +581,8 @@ setJSONArray FUNCTION2 JSONArray_setJSONArray_
setJSONObject FUNCTION2 JSONArray_setJSONObject_
setString FUNCTION2 JSONArray_setString_
size FUNCTION2 JSONArray_size_
toIntArray FUNCTION2 JSONArray_toIntArray_
toStringArray FUNCTION2 JSONArray_toStringArray_
JSONObject KEYWORD5 JSONObject
getBoolean FUNCTION2 JSONObject_getBoolean_
getFloat FUNCTION2 JSONObject_getFloat_
Expand Down Expand Up @@ -751,6 +755,7 @@ random2D FUNCTION2 PVector_random2D_
random3D FUNCTION2 PVector_random3D_
rotate FUNCTION2 PVector_rotate_
set FUNCTION2 PVector_set_
setHeading FUNCTION2 PVector_setHeading_
setMag FUNCTION2 PVector_setMag_
sub FUNCTION2 PVector_sub_
quad FUNCTION1 quad_
Expand Down Expand Up @@ -847,6 +852,7 @@ shuffle FUNCTION2 StringList_shuffle_
size FUNCTION2 StringList_size_
sort FUNCTION2 StringList_sort_
sortReverse FUNCTION2 StringList_sortReverse_
toArray FUNCTION2 StringList_toArray_
upper FUNCTION2 StringList_upper_
stroke FUNCTION1 stroke_
strokeCap FUNCTION1 strokeCap_
Expand Down Expand Up @@ -911,6 +917,13 @@ unbinary FUNCTION1 unbinary_
unhex FUNCTION1 unhex_
updatePixels FUNCTION1 updatePixels_
vertex FUNCTION1 vertex_
windowMove FUNCTION1 windowMove_
windowMoved FUNCTION1 windowMoved_
windowRatio FUNCTION1 windowRatio_
windowResizable FUNCTION1 windowResizable_
windowResize FUNCTION1 windowResize_
windowResized FUNCTION1 windowResized_
windowTitle FUNCTION1 windowTitle_
XML KEYWORD5 XML
addChild FUNCTION2 XML_addChild_
format FUNCTION2 XML_format_
Expand Down