c# 求某点绕某点旋转1度后坐标
时间: 2023-07-27 17:26:59 浏览: 207
假设要求点P1(x1, y1)绕点P0(x0, y0)逆时针旋转1度后的坐标P2(x2, y2),可以按照以下步骤计算:
1. 将点P1(x1, y1)平移到原点,即:将x1, y1分别减去x0, y0,得到点P1`(x1`, y1`),其中,x1` = x1 - x0,y1` = y1 - y0。
2. 计算点P1`(x1`, y1`)绕原点逆时针旋转1度后的坐标P2`(x2`, y2`)。根据旋转变换的公式可以得到:
x2` = x1` * cos(a) - y1` * sin(a)
y2` = x1` * sin(a) + y1` * cos(a)
其中,a = 1 * pi / 180,即1度对应的弧度值。
3. 将点P2`(x2`, y2`)平移到点P0(x0, y0),即:将x2`, y2`分别加上x0, y0,得到点P2(x2, y2),其中,x2 = x2` + x0,y2 = y2` + y0。
综上所述,可以写出C#代码实现:
```
double x0 = ...; // P0的横坐标
double y0 = ...; // P0的纵坐标
double x1 = ...; // P1的横坐标
double y1 = ...; // P1的纵坐标
double a = 1 * Math.PI / 180; // 1度对应的弧度值
double x1_ = x1 - x0;
double y1_ = y1 - y0;
double x2_ = x1_ * Math.Cos(a) - y1_ * Math.Sin(a);
double y2_ = x1_ * Math.Sin(a) + y1_ * Math.Cos(a);
double x2 = x2_ + x0;
double y2 = y2_ + y0;
// 输出旋转后的坐标
Console.WriteLine("P2({0}, {1})", x2, y2);
```
其中,x0, y0, x1, y1分别表示点P0, P1的横纵坐标,可以根据实际情况进行替换。
阅读全文
相关推荐

















