Rotate a point to another point in 2D

I want to know how to work out new coordinates for a point when turning an angle relative to another point.

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

This is required to enable drawing a polygon between two on-screen controls. I can not use and rotate the image.

From what I have examined so far, what further complicates the problem is that the origin of the screen is in the upper left corner.

+51
math c # rotation angle
Apr 24 '09 at 15:55
source share
3 answers

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

 p'x = cos (theta) * (px-ox) - sin (theta) * (py-oy) + ox
 p'y = sin (theta) * (px-ox) + cos (theta) * (py-oy) + oy
+126
Apr 24 '09 at 16:03
source share

If you use GDI + for this, you can use the Transform methods of the Graphics object:

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

Then draw the actual material.

+8
Apr 24 '09 at 15:58
source share

If you have a System.Windows.Media , you can use the built-in conversions:

  using System.Windows.Media; var transform = new RotateTransform() {Angle = angleInDegrees, CenterX = center.X, CenterY = center.Y}; var transformedPoint = transform.Transform(point); 
+2
Aug 02 '14 at
source share



All Articles