This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.
Name 
atan2() 
Examples  void draw() {
background(204);
translate(width/2, height/2);
float a = atan2(mouseYheight/2, mouseXwidth/2);
rotate(a);
rect(30, 5, 60, 10);
}

Description 
Calculates the angle (in radians) from a specified point to the coordinate origin as measured from the positive xaxis. Values are returned as a float in the range from PI to PI. The atan2() function is most often used for orienting geometry to the position of the cursor. Note: The ycoordinate of the point is the first parameter, and the xcoordinate is the second parameter, due the the structure of calculating the tangent.

Syntax  atan2(y, x) 
Parameters 
y 
float: ycoordinate of the point 
x 
float: xcoordinate of the point 

Returns  float 
Related  tan()

Updated on February 10, 2016 00:49:39am EST