Rotate image math (C#)

前端 未结 6 2255
醉话见心
醉话见心 2020-12-05 08:39

I have an image with two points, aligned something like this:

|----------------|
|                |
|    .           |
|                |
|          .     |
         


        
6条回答
  •  囚心锁ツ
    2020-12-05 09:11

    First find the centre point:

    Point p = new Point((x1-x2)/2, (y1-y2)/2)
    

    Then use trigonomentry to solve for the angle. I'm going to assume we have rebased the origin to our central point so I now have a new x3 and y3 to one of the points.

    hypotenuse = SqrRt(x3^2 + y3^2)
    

    We are solving for the unknown angle TH

    Sin(TH) = opposite / hypotenuse
    

    So to solve for TH we need:

    TH = Asin(y3 / hypotenuse)
    

    Rotate by TH.

    See Wikipedia for trigonometric functions reference

提交回复
热议问题