CPoint2D CTraverseNetCalcu::LP2CP(const CPoint2D& Point, CRect& rect)//逻辑坐标转客户区坐标 { CPoint2D P; P = Point; P.y_draw = rect.Height() - (Point.x - x_min) * k; P.x_draw = (Point.y - y_min) * k; P.y_draw -= rect.Width() / 10; P.x_draw += rect.Height() / 10; return P; }
时间: 2023-12-03 18:03:23 浏览: 140
这段代码实现了一个名为`LP2CP`的函数,用于将逻辑坐标转换为客户区坐标。
该函数接受一个逻辑坐标`Point`和一个矩形区域`rect`作为输入参数。
首先,创建一个空的`CPoint2D`对象`P`。
然后,将输入的逻辑坐标的x轴值减去`x_min`并乘以`k`,将结果赋值给`P.y_draw`,表示转换后的y轴值。
接着,将输入的逻辑坐标的y轴值减去`y_min`并乘以`k`,将结果赋值给`P.x_draw`,表示转换后的x轴值。
然后,将转换后的y轴值减去客户区宽度的1/10,将结果赋值给`P.y_draw`,表示向上调整了一定比例。
最后,将转换后的x轴值加上客户区高度的1/10,将结果赋值给`P.x_draw`,表示向右调整了一定比例。
最终,返回转换后的客户区坐标`P`。
相关问题
在MFC中,已知一个矩形在坐标系中间且四个顶点坐标确定,求它关于原点旋转45度后的顶点坐标的代码
在 MFC 中,可以利用 `CPoint` 类来表示点的坐标,利用 `CRect` 类来表示矩形。已知矩形的四个顶点坐标为 `(x1, y1)`, `(x2, y2)`, `(x3, y3)`, `(x4, y4)`,则可以利用以下代码计算出该矩形绕原点逆时针旋转45度后的四个顶点坐标:
```
#include <math.h>
CPoint RotatePoint(const CPoint& pt, double angle)
{
// 将点 pt 绕原点逆时针旋转 angle 度后的新坐标
double radian = angle * M_PI / 180.0;
int new_x = (int)(pt.x * cos(radian) - pt.y * sin(radian));
int new_y = (int)(pt.x * sin(radian) + pt.y * cos(radian));
return CPoint(new_x, new_y);
}
CRect RotateRect(const CRect& rect, double angle)
{
CPoint pt1(rect.left, rect.top);
CPoint pt2(rect.right, rect.top);
CPoint pt3(rect.right, rect.bottom);
CPoint pt4(rect.left, rect.bottom);
pt1 = RotatePoint(pt1, angle);
pt2 = RotatePoint(pt2, angle);
pt3 = RotatePoint(pt3, angle);
pt4 = RotatePoint(pt4, angle);
int left = min(min(pt1.x, pt2.x), min(pt3.x, pt4.x));
int top = min(min(pt1.y, pt2.y), min(pt3.y, pt4.y));
int right = max(max(pt1.x, pt2.x), max(pt3.x, pt4.x));
int bottom = max(max(pt1.y, pt2.y), max(pt3.y, pt4.y));
return CRect(left, top, right, bottom);
}
```
这里定义了两个函数:`RotatePoint` 和 `RotateRect`。`RotatePoint` 函数用于将点 `pt` 绕原点逆时针旋转指定的角度 `angle` 度,返回旋转后的新坐标。`RotateRect` 函数则利用 `RotatePoint` 函数来计算出矩形的四个顶点旋转后的坐标,再根据旋转后的四个顶点坐标来确定旋转后的矩形的位置和大小。最终,`RotateRect` 函数返回旋转后的矩形。
在调用 `RotateRect` 函数时,只需要将原始矩形作为参数传入即可。例如:
```
CRect rect(x1, y1, x4, y4);
CRect rotated_rect = RotateRect(rect, 45.0);
```
其中,`x1`、`y1`、`x4`、`y4` 分别表示原始矩形的左上角和右下角的坐标。`rotated_rect` 即为旋转后的矩形。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)