我正在编写一个游戏。我需要知道如何围绕给定角度,将点a绕点b旋转。我在java中编写这个功能,并且它将成为我的类Point的一部分。
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;
这种方法使用旋转矩阵。 "point" 是您的点 a,"center" 是您的点 b。