Language \ Environment \ Comparison
 
Index
 
  The Processing 1.0 _ALPHA_ Reference is a work in progress.
If you see any errors or have any comments, please write to: reas at groupc.net
Name  

atan2()

   
Examples  
void loop() { 
  background(204); 
  translate(width/2, height/2); 
  float a = atan2(mouseY-height/2, mouseX-width/2); 
  rotate(a); 
  rect(-12, -5, 24, 10); 
} 
Description   Calculates the angle (in radians) from a specified point to the coordinate origin as measured from the positive x-axis. 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 y-coordinate of the point is the first parameter and the x-coordinate is the second due the the structure of calculating the tangent.
   
Syntax  
atan2(y, x); 
   
Parameters  
y   int or float: y-coordinate of the point

x   int or float: x-coordinate of the point

   
Returns   float
   
Usage   Web & Application
   
Related   tan()
   
© 2004 - 2001 Massachusetts Institute of Technology and Interaction Design Institute Ivrea
Processing is an open project initiated by Ben Fry and Casey Reas