Proper Trigonometry For Rotating A Point Around The Origin

后端 未结 3 424
悲哀的现实
悲哀的现实 2020-12-10 12:05

Do either of the below approaches use the correct mathematics for rotating a point? If so, which one is correct?

POINT rotate_point(float cx,float cy,float          


        
3条回答
  •  难免孤独
    2020-12-10 12:54

    It depends on how you define angle. If it is measured counterclockwise (which is the mathematical convention) then the correct rotation is your first one:

    // This?
    float xnew = p.x * c - p.y * s;
    float ynew = p.x * s + p.y * c;
    

    But if it is measured clockwise, then the second is correct:

    // Or This?
    float xnew = p.x * c + p.y * s;
    float ynew = -p.x * s + p.y * c;
    

提交回复
热议问题