How to rotate a vertex around a certain point?

前端 未结 6 1383
南旧
南旧 2020-11-29 04:09

Imagine you have two points in 2d space and you need to rotate one of these points by X degrees with the other point acting as a center.

float distX = Math.a         


        
6条回答
  •  鱼传尺愫
    2020-11-29 04:36

    You need a 2-d rotation matrix http://en.wikipedia.org/wiki/Rotation_matrix

    Your new point will be

     newX = centerX + ( cosX * (point2X-centerX) + sinX * (point2Y -centerY))
     newY = centerY + ( -sinX * (point2X-centerX) + cosX * (point2Y -centerY))
    

    because you are rotating clockwise rather than anticlockwise

提交回复
热议问题