【工具类】Java 平面一点绕另一点旋转后的坐标
点A(pointX,pointY) 绕 中心点O(centerX,centerY) 旋转angle角度之后 得到点 B(newX,newY)
/**
* 点A(pointX,pointY) 绕 中心点O(centerX,centerY) 旋转angle角度之后 得到点 B(newX,newY)
*
* @param pointX 点A横坐标
* @param pointY 点A纵坐标
* @param centerX 中心点O横坐标
* @param centerY 中心点O横坐标
* @param angle 旋转角度,+逆时针,-顺时针
* @return 旋转后的点 B(newX,newY)
*/
public static double[] rotatePoint(double pointX, double pointY,
double centerX, double centerY, double angle) {
angle = new Double(Math.toRadians(angle));
double newX = new Double((pointX - centerX) * Math.cos(angle) + (pointY - centerY) * Math.sin(angle) + centerX);
double newY = new Double(-(pointX - centerX) * Math.sin(angle) + (pointY - centerY) * Math.cos(angle) + centerY);
double[] result = {newX, newY};
return result;
}
测试
public static void main(String[] args) {
double pointX = 84;
double pointY = 250;
double centerX = 250;
double centerY = 250;
int angle = -90;
double[] point = rotatePoint(pointX, pointY, centerX, centerY, angle);
System.out.println(point[0] + "," + point[1]);
}
https://blog.csdn.net/lnx1824/article/details/84018762