#include <iostream> #include <cmath> struct Point { double x; double y; }; // 计算点p围绕点center逆时针旋转angle度后的新坐标 Point rotatePoint(const Point& p, const Point& center, double angle) { double radians = angle * M_PI / 180.0; // 将角度转换为弧度 double cosValue = std::cos(radians); double sinValue = std::sin(radians); // 应用旋转矩阵变换 double newX = (p.x - center.x) * cosValue - (p.y - center.y) * sinValue + center.x; double newY = (p.x - center.x) * sinValue + (p.y - center.y) * cosValue + center.y; return { newX, newY }; } int main() { Point p{ 1.0, 1.0 }; // 需要旋转的点的坐标 Point center{ 0.0, 0.0 }; // 中心点的坐标 double angle = 45.0; // 旋转角度 Point rotatedPoint = rotatePoint(p, center, angle); std::cout << "旋转后的坐标: (" << rotatedPoint.x << ", " << rotatedPoint.y << ")" << std::endl; return 0; }