how to rotate a point around another point

后端 未结 1 916
野趣味
野趣味 2020-12-19 16:29

I am writing a game. I need to know how to rotate point a around point b by a given number of degrees. I am writing this in java and it is going to be part of my class, Poin

相关标签:
1条回答
  • 2020-12-19 17:10
    double x1 = point.x - center.x;
    double y1 = point.y - center.y;
    
    double x2 = x1 * Math.cos(angle) - y1 * Math.sin(angle));
    double y2 = x1 * Math.sin(angle) + y1 * Math.cos(angle));
    
    point.x = x2 + center.x;
    point.y = y2 + center.y;
    

    This approach uses rotation matrices. "point" is your point a, "center" is your point b.

    0 讨论(0)
提交回复
热议问题