在vs环境下,使用git管理项目开发,在分支中,写出实现任意一个带角度的坐标点,旋转一定角度后,获取旋转点坐标
时间: 2023-04-10 22:01:13 浏览: 56
可以使用以下代码实现:
```c++
#include <iostream>
#include <cmath>
using namespace std;
struct Point {
double x;
double y;
};
Point rotate(Point p, double angle) {
double rad = angle * M_PI / 180.0;
double cosVal = cos(rad);
double sinVal = sin(rad);
Point result;
result.x = p.x * cosVal - p.y * sinVal;
result.y = p.x * sinVal + p.y * cosVal;
return result;
}
int main() {
Point p = {1.0, 1.0};
double angle = 45.0;
Point rotated = rotate(p, angle);
cout << "Rotated point: (" << rotated.x << ", " << rotated.y << ")" << endl;
return 0;
}
```
这段代码实现了一个 `Point` 结构体,包含了 `x` 和 `y` 两个坐标值。`rotate` 函数接受一个 `Point` 类型的参数和一个角度值,返回旋转后的坐标点。在 `main` 函数中,我们定义了一个点 `p` 和一个角度值 `angle`,然后调用 `rotate` 函数得到旋转后的坐标点,并输出结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)