Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have computer program I am writing where I need to calculate the position of a point(called P) when rotated around another point.

I am attempting to come up with a general function/formula I can use to calculate this point P but my Maths is a little weak & I cannot identify what arc/tangent formula I am meant to use.

Can you assist me to come up with a formula I can use to calculate point P for rotations that can be both positive & negative?

enter image description here

I know how to calulate the length of the line between points (14,446) & (226,496) but not how to calculate the blue point x,y position - BTW: the length of this line is the same as the line between the blue point & (14,446)

len = sqrt( (496-446)^2 + (226-14)^2 );
    = 227.56;
share|cite|improve this question
up vote 3 down vote accepted

Let's say that the point you're rotating is $(p_x,p_y)$ (your lower-right red point), that the center of rotation is $(c_x,c_y)$ (your middle red point), and that the rotation has magnitude $\theta$ (positive being counterclockwise, your angle being $165°$). Then the resulting point (your blue point) is at $$(c_x+(p_x-c_x)\cos\theta+(c_y-p_y)\sin\theta,\;\;c_y+(p_y-c_y)\cos\theta+(p_x-c_x)\sin\theta).$$

share|cite|improve this answer
thanks for the formula. When you mention magnitude what do you mean? Also what happens if 0 degrees in programming is actually 90 degrees, do I minus 90 from every angle to get the correct result? – Jake M Jan 28 '12 at 6:28
@JakeM: By "magnitude of the rotation" I mean the size and direction of the rotation—it shouldn't matter if your programming 0° is where a mathematical 90° would be, since that doesn't affect how far your red point has to rotate to become your blue point. Positive angles will rotate in the counterclockwise direction, while negative angles will rotate in the clockwise direction (this is assuming that your positive $y$-axis is 90° counterclockwise from your positive $x$-axis; if it's 90° clockwise, then positive angles are clockwise as well). – Isaac Jan 28 '12 at 6:33
So the answer would be: var mid = {x: 14+((226-14)*Math.cos(165))+((496-446)*Math.sin(165)), y: 446+((496-446)*Math.cos(165))+((226-14)*Math.sin(165))}; – Jake M Jan 28 '12 at 6:40
@JakeM: Assuming Math.sin and Math.cos are expecting angles in degrees, var mid = {x: 14+((226-14)*Math.cos(165))+((446-496)*Math.sin(165)), y: 446+((496-446)*Math.cos(165))+((226-14)*Math.sin(165))}; (swap 446 and 496 in the expression for x) should be right, but looking at your picture again, it looks like your positive $y$-axis goes downward ($0$ at the top, positive below that), so you may need to change the 165 to -165. – Isaac Jan 28 '12 at 6:47
I could kiss you! :D lol I've been struggling with this for ages. Thank you math genius – Jake M Jan 28 '12 at 6:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.