processing-docs
processing-docs copied to clipboard
Indicate rotation direction for `PVector::rotate()`
Issue description
Indicate the direction that the vector will be rotated in, in order to avoid any ambiguity.
URL(s) of affected page(s)
https://processing.org/reference/PVector_rotate_.html
Proposed fix
Rotates a vector anticlockwise by the specified angle (2D vectors only), while maintaining the same magnitude.
Or add a sentence "Positive angles will rotate the vector anticlockwise."
Note that the documentation for rotate says:
https://processing.org/reference/rotate_.html
Positive numbers rotate objects in a clockwise direction and negative numbers rotate in the couterclockwise direction.
But it turns out a positive angle actually rotates in the direction from the x-axis towards the y-axis.
In the standard coordinate system used in Processing, where the x-axis points right and the y-axis points down,
this is indeed clockwise. However, if one flips the y-axis with scale(1,-1) then the y-axis points up - and we have a standard coordinate system. Then a positive angle will rotate in the counterclockwise direction (aka from the x-axis towards the y-axis).
If the text is revised, consider "a postive angle with rotate in the direction from the x-axis towards the y-axis". Or of "clockwise/anticlockwise" is used, add a note on how the x-axis and y-axis needs to be directed.
An example ready to experiment with:
int yscale = 1;
void mousePressed() {
yscale *= -1;
}
void setup() {
size(400,400);
rectMode(CENTER);
frameRate(1);
fill(255);
}
void draw() {
background(200);
text(str(yscale),20,20);
translate(200,200);
scale(1,yscale);
rotate(0.1*frameCount);
rect(0,0,100,100);
}