Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper Trigonometry For Rotating A Point Around The Origin

Do either of the below approaches use the correct mathematics for rotating a point? If so, which one is correct?

POINT rotate_point(float cx,float cy,float angle,POINT p)
{
  float s = sin(angle);
  float c = cos(angle);

  // translate point back to origin:
  p.x -= cx;
  p.y -= cy;

  // Which One Is Correct:
  // This?
  float xnew = p.x * c - p.y * s;
  float ynew = p.x * s + p.y * c;
  // Or This?
  float xnew = p.x * c + p.y * s;
  float ynew = -p.x * s + p.y * c;

  // translate point back:
  p.x = xnew + cx;
  p.y = ynew + cy;
}
like image 452
Joshua Avatar asked Jul 02 '10 00:07

Joshua


People also ask

How do you rotate a point around the origin?

Direction of Rotation: Counterclockwise or clockwise direction. Positive rotations are counterclockwise. Negative rotations are clockwise. For example, to rotate the point (2, 5) counterclockwise about the origin by 90 degrees, we use the rule: (x,y)→(−y,x) ( x , y ) → ( − y , x ) .

What is the rule for rotating 90 degrees about the origin?

90 Degree Rotation When rotating a point 90 degrees counterclockwise about the origin our point A(x,y) becomes A'(-y,x). In other words, switch x and y and make y negative.


1 Answers

From Wikipedia

To carry out a rotation using matrices the point (x, y) to be rotated is written as a vector, then multiplied by a matrix calculated from the angle, θ, like so:

https://upload.wikimedia.org/math/0/e/d/0ed0d28652a45d730d096a56e2d0d0a3.png

where (x′, y′) are the co-ordinates of the point after rotation, and the formulae for x′ and y′ can be seen to be

alt text

like image 185
Alexandros Gezerlis Avatar answered Oct 11 '22 10:10

Alexandros Gezerlis