views:

2866

answers:

3

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.

+1  A: 

If you are using GDI+ to do that, you can use Transform methods of the Graphics object:

graphics.TranslateTransform(point of origin);
graphics.RotateTransform(rotation angle);

Then draw the actual stuff.

Mehrdad Afshari
A: 

I have nothing to say.

jw
I think that was a bit cheeky, but funny. It does seem like the type of question you can find in about one minute using Google or Wikipedia. I think you should responded with "Are you feeling lucky?" link.
Erich Mirabal
+13  A: 

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
Ben Alpert
Do you have the 3D version in memory too? :)
Mehrdad Afshari
Nope, just 2D. ;)
Ben Alpert
Would theta be in radiants and degrees ? Forgive if dumb -Q- ..
lb
It depends on which library you're using for the trig functions. In C, you need to pass in radians.
Ben Alpert