Retrieve a positive or a negative angle from 3 points

前端 未结 4 404
日久生厌
日久生厌 2020-12-17 03:13

I am rotating points around a center point in 2D space. The points are the center point, the old mouse position, and the new mouse position. My rotation function works fin

4条回答
  •  旧时难觅i
    2020-12-17 04:06

    It seems like all you need to do is

    angle = angle > Math.PI ? angle - 2*Math.PI : angle;
    

    at the end of your code. That will give you a clockwise rotation to the right of the line defined by centerPoint and oldPoint, and counter-clockwise to the left of it, regardless of orientation.

提交回复
热议问题