#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# How to define an origin for atan2()

edited March 2018

The p5js page for atan2 states that it works in the following way:

Calculates the angle (in radians) from a specified point to the coordinate origin as measured from the positive x-axis.

However, I would like to calculate the angle between a set of points other than the origin. Is there any way to do this, and if so, can I get a pointer towards the right track? Thanks in advance! :)

Tagged:

I figured out solving my problem rather quickly. Reading the documentation all the way really helps :P

I realized that I could use atan2() in the form of `atan2(y2 - y1, x2 - x1)`. I then applied that to a sprite rotation (p5.play.js) by converting the radians angle to degrees (since atan2() returns an angle in radians, and p5.play's rotation method needs it in degrees). This got me my final code:
``````p.rotation = degrees(atan2(camera.mouseY - p.position.y, camera.mouseX - p.position.x));