//寻找离目标最近的移动坐标 并提取其父路径 static List<Vector2> FindNearestMove(APoint _a, List<Vector2> c_MoveRange, Vector2 c_position) { List<Vector2> vectors = new List<Vector2>(); Vector2 _v = new Vector2(_a.x, _a.y); //如果移动范围内不包含位置则继续 while (!c_MoveRange.Contains(_v) && _a.father != null) { _a = _a.father; _v = new Vector2(_a.x, _a.y); } //如果找到起点位置跳出 while (!(_v == c_position)) { _v = new Vector2(_a.x, _a.y); vectors.Add(_v); _a = _a.father; } return (vectors); }
时间: 2024-01-15 08:03:27 浏览: 24
这是一段C#代码,它的功能是在一个移动范围内寻找距离目标最近的移动坐标,并提取其父路径。首先,它将传入的起点坐标转换成一个APoint对象,然后通过循环判断当前点是否在移动范围内,并且还要判断父节点是否为空,如果不为空则继续往上找,直到找到范围内的点或者到达起点。然后通过另一个循环,从找到的点开始,一直往上找到起点,并将路径存储在一个列表中,最后返回这个列表。
相关问题
使用Python提取dwg文件中的线条型表格,并将内容输出到excel,给出代码
要使用Python提取dwg文件中的线条型表格,并将内容输出到Excel,可以使用Python的AutoCAD API库,例如pyautocad或comtypes库。下面是一个基本的示例代码:
```python
import openpyxl
from pyautocad import Autocad, APoint
# 创建一个新的Excel文件
wb = openpyxl.Workbook()
ws = wb.active
# 连接到AutoCAD
acad = Autocad()
# 打开DWG文件
doc = acad.Application.Documents.Open("path/to/dwg/file.dwg")
# 获取所有的线条
lines = doc.ModelSpace.QueryInterface(comtypes.gen.Autodesk.AutoCAD.Interop.Common.IAcadEntity).GetObjectsByEntityName("AcDbLine")
# 创建表头
ws['A1'] = "X1"
ws['B1'] = "Y1"
ws['C1'] = "X2"
ws['D1'] = "Y2"
# 将每个线条的坐标输出到Excel
for i, line in enumerate(lines):
ws.cell(row=i+2, column=1, value=line.StartPoint[0])
ws.cell(row=i+2, column=2, value=line.StartPoint[1])
ws.cell(row=i+2, column=3, value=line.EndPoint[0])
ws.cell(row=i+2, column=4, value=line.EndPoint[1])
# 保存Excel文件
wb.save("path/to/excel/file.xlsx")
```
上面的代码使用pyautocad库连接到AutoCAD并打开DWG文件。然后,它获取所有的线条,将表头添加到Excel文件,并将每个线条的起始点和终止点输出到Excel文件中。最后,代码保存Excel文件。请注意,该代码仅提取了线条的坐标,如果需要提取其他属性,请修改代码以满足您的需求。
oc之mac坐标转换
在 macOS 中,有多种方式进行坐标转换。以下是其中两种常见的方法:
1. 使用坐标转换函数
在 macOS 中,可以使用以下函数将一个坐标点从一个坐标系转换到另一个坐标系:
```objc
NSPoint NSConvertPoint(NSPoint aPoint, NSRect fromRect, NSRect toRect);
```
其中,`aPoint` 是需要转换的坐标点,`fromRect` 是源坐标系(通常是屏幕坐标系),`toRect` 是目标坐标系(通常是视图坐标系)。例如,要将屏幕上的坐标点转换为视图上的坐标点,可以这样写:
```objc
NSPoint screenPoint = {100, 100}; // 屏幕坐标系
NSRect viewFrame = [self.view frame]; // 视图坐标系
NSPoint viewPoint = NSConvertPoint(screenPoint, nil, viewFrame); // 转换坐标
```
2. 使用坐标转换矩阵
另一种常见的方式是使用坐标转换矩阵。在 macOS 中,可以使用以下方法创建一个坐标转换矩阵:
```objc
NSAffineTransform *transform = [NSAffineTransform transform];
[transform scaleXBy:scaleX yBy:scaleY];
[transform rotateByDegrees:rotation];
[transform translateXBy:translateX yBy:translateY];
```
其中,`scaleX` 和 `scaleY` 是缩放因子,`rotation` 是旋转角度,`translateX` 和 `translateY` 是平移量。例如,要将屏幕上的坐标点转换为视图上的坐标点,可以这样写:
```objc
NSAffineTransform *transform = [NSAffineTransform transform];
[transform translateXBy:-viewFrame.origin.x yBy:-viewFrame.origin.y]; // 将视图坐标系移到原点
[transform concat]; // 应用坐标转换矩阵
NSPoint screenPoint = {100, 100}; // 屏幕坐标系
NSPoint viewPoint = [self.view convertPoint:screenPoint fromView:nil]; // 转换坐标
```
这里使用了 `NSView` 类的 `convertPoint:fromView:` 方法,将屏幕上的坐标点转换为视图上的坐标点。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)