Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate a point by another point in 2D

I want to know how to work out the new co-ordinates for a point when rotated by an angle relative to another point.

I have a block arrow and want to rotate it by an angle theta relative to a point in the middle of the base of the arrow.

This is required to allow me to draw a polygon between 2 onscreen controls. I can't use and rotate an image.

From what I have considered so far what complicates the matter further is that the origin of a screen is in the top left hand corner.

like image 750
James Avatar asked Apr 24 '09 15:04

James


1 Answers

If you rotate point (px, py) around point (ox, oy) by angle theta you'll get:

 p'x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox p'y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy 
like image 103
Sophie Alpert Avatar answered Oct 24 '22 23:10

Sophie Alpert