当前位置: 首页 > wzjs >正文

境外建设网站贴吧天津注册公司流程和费用标准

境外建设网站贴吧,天津注册公司流程和费用标准,网络组建与维护试题,wordpress图片中文Grasshopper Python点集排序:带索引的Z字形排序算法 1. 功能介绍 这段代码实现了一个在Grasshopper中的点集排序功能,不仅可以将空间中的点按照Y坐标分组并在每组内按X坐标排序,还能追踪每个点的原始索引位置。 2. 输入输出参数 输入参数&…

Grasshopper Python点集排序:带索引的Z字形排序算法

在这里插入图片描述

1. 功能介绍

这段代码实现了一个在Grasshopper中的点集排序功能,不仅可以将空间中的点按照Y坐标分组并在每组内按X坐标排序,还能追踪每个点的原始索引位置。

2. 输入输出参数

  • 输入参数:
    • x: 待排序的点集(Point List)
    • t: 容差值(Number),默认2000
  • 输出参数:
    • a: 排序后的点集(Point List)
    • i: 排序后点的原始索引(Number List)

3. 核心算法流程

输入点集
点集是否为空?
创建点索引对
返回None
按Y坐标分组
组内按X排序
提取排序后的点
提取对应的索引
输出排序点集
输出索引列表

4. 代码解析

4.1 点索引对的创建和处理

points_with_index = list(enumerate(x))
  • 使用enumerate()创建(索引, 点)对
  • 将每个点与其原始位置绑定

4.2 分组函数

def groupPointsByY(points_with_index, tolerance):points_with_index = sorted(points_with_index, key=lambda pair: pair[1].Y)groups = []current_group = [points_with_index[0]]current_y = points_with_index[0][1].Y
  • 函数接收点索引对和容差值
  • 使用lambda函数访问点的Y坐标进行排序
  • pair[1]访问点对象,pair[0]访问索引

4.3 分组逻辑

for p in points_with_index[1:]:if abs(p[1].Y - current_y) <= tolerance:current_group.append(p)else:groups.append(current_group)current_group = [p]current_y = p[1].Y
  • 遍历点索引对
  • 基于Y坐标差值分组
  • 保持索引与点的关联

4.4 排序和结果提取

for group in grouped_points:group_sorted = sorted(group, key=lambda pair: pair[1].X)for index, point in group_sorted:sorted_points.append(point)sorted_indices.append(index)
  • 组内按X坐标排序
  • 分别提取点和索引
  • 维护排序后的两个列表

5. Python语法要点

5.1 元组拆包

for index, point in group_sorted:
  • 直接将元组拆分为两个变量
  • 简化数据访问

5.2 Lambda表达式

key=lambda pair: pair[1].X
  • 用于定义排序键函数
  • 访问元组中点对象的坐标

5.3 列表操作

sorted_points.append(point)
sorted_indices.append(index)
  • 使用append()逐个添加元素
  • 维护两个平行列表

6. 数据结构

6.1 点索引对

(index, point) 结构:
- index: 原始位置
- point: 点对象- X: X坐标- Y: Y坐标- Z: Z坐标

6.2 分组结构

groups = [[(index1, point1), (index2, point2), ...],  # 第一组[(index3, point3), (index4, point4), ...],  # 第二组...
]

左上角向右上角排序↗

# GH Python Component的设置:
# x: 输入点集(point list)
# t: 输入容差值(number),默认值可设为2000
# a: 输出排序后的点集(point list)
# i: 输出排序后点的原始索引(number list)def groupPointsByY(points_with_index, tolerance):"""将Y坐标相近的点分组"""if not points_with_index:return []# 按Y坐标排序,注意points_with_index中的每个元素是(index, point)的元组points_with_index = sorted(points_with_index, key=lambda pair: pair[1].Y)groups = []current_group = [points_with_index[0]]current_y = points_with_index[0][1].Y  # 使用pair[1]访问点# 遍历所有点,根据Y坐标差值分组for p in points_with_index[1:]:if abs(p[1].Y - current_y) <= tolerance:  # 使用pair[1]访问点current_group.append(p)else:groups.append(current_group)current_group = [p]current_y = p[1].Y  # 使用pair[1]访问点groups.append(current_group)return groupsif x:  # 确保输入不为空# 设置默认容差值tolerance = t if t is not None else 2000# 创建带索引的点列表points_with_index = list(enumerate(x))  # 创建(索引,)对的列表# 将点按Y坐标分组grouped_points = groupPointsByY(points_with_index, tolerance)# 对每组内的点按X坐标排序sorted_points = []sorted_indices = []for group in grouped_points:# 按X坐标排序,同时保持索引group_sorted = sorted(group, key=lambda pair: pair[1].X)  # 使用pair[1]访问点# 分离点和索引for index, point in group_sorted:sorted_points.append(point)sorted_indices.append(index)a = sorted_pointsi = sorted_indices
else:a = Nonei = None

左上角向右下角排序↘

# GH Python Component的设置:
# x: 输入点集 (point list)
# t: 输入容差值 (number),默认值可设为2000
# a: 输出排序后的点集 (point list)
# i: 输出排序后点的原始索引 (number list)def groupPointsByY(points_with_index, tolerance):"""将Y坐标相近的点分组,并按Y值从大到小排序,确保按从上到下进行分组"""if not points_with_index:return []# 修改:按Y坐标从大到小排序(最高的点在前),reverse=Truepoints_with_index = sorted(points_with_index, key=lambda pair: pair[1].Y, reverse=True)groups = []current_group = [points_with_index[0]]current_y = points_with_index[0][1].Y  # 当前组参考的Y值# 遍历剩余的点,若两点Y坐标差值在容差范围内,则归为一组for p in points_with_index[1:]:if abs(p[1].Y - current_y) <= tolerance:current_group.append(p)else:groups.append(current_group)current_group = [p]current_y = p[1].Ygroups.append(current_group)return groupsif x:  # 确保输入不为空# 设置默认容差值tolerance = t if t is not None else 2000# 为每个点创建一个(原始索引,)的元组列表points_with_index = list(enumerate(x))# 按Y坐标(从上到下)分组grouped_points = groupPointsByY(points_with_index, tolerance)sorted_points = []sorted_indices = []# 对每组内的点按X坐标从小到大排序(从左至右)for group in grouped_points:group_sorted = sorted(group, key=lambda pair: pair[1].X)for index, point in group_sorted:sorted_points.append(point)sorted_indices.append(index)a = sorted_pointsi = sorted_indices
else:a = Nonei = None

文章转载自:

http://zfbjhdBe.dmLgq.cn
http://qv2JMmJp.dmLgq.cn
http://vdpiBzL8.dmLgq.cn
http://OyJt8zvM.dmLgq.cn
http://nwfhye90.dmLgq.cn
http://I4lCpAG6.dmLgq.cn
http://xkjdn7pu.dmLgq.cn
http://XIwKklZn.dmLgq.cn
http://Ap7WW4AL.dmLgq.cn
http://Mx25etjL.dmLgq.cn
http://g0DVD3Cc.dmLgq.cn
http://mJJe11yR.dmLgq.cn
http://XIz98lnT.dmLgq.cn
http://IIb8J8No.dmLgq.cn
http://h8WPOypB.dmLgq.cn
http://8DS8fFxY.dmLgq.cn
http://DnV0dh3T.dmLgq.cn
http://T9SoSWpc.dmLgq.cn
http://OkYajmwa.dmLgq.cn
http://jz2WE61r.dmLgq.cn
http://uUEoWKir.dmLgq.cn
http://xJeClTES.dmLgq.cn
http://ghVSZfyZ.dmLgq.cn
http://E9sEVZYa.dmLgq.cn
http://oHwSOhRS.dmLgq.cn
http://zFk6hIAH.dmLgq.cn
http://ZLiVuiJh.dmLgq.cn
http://7uzlSzZf.dmLgq.cn
http://VYA9SdaR.dmLgq.cn
http://ompyTHFk.dmLgq.cn
http://www.dtcms.com/wzjs/651322.html

相关文章:

  • 怎么做盗版网站智趣游戏型网站开发
  • 织梦网站模板安装教程wordpress集成到app
  • 怎么做免费视频网站管理咨询项目
  • 医院网站设计与实现西宁高端网站制作
  • 郑州 科技有限公司 网站建设建筑工人信息平台
  • 湖州 网站建设公司哪家好备案网站建设书
  • 北京网站建设appwordpress支持pdf
  • 个性定制网站有哪些wordpress 函数手册
  • 阿里云网站建设方案书大气微电影类网站织梦模板完整版
  • 南京市浦口区建设局网站网站空间是虚拟主机吗
  • 东莞企业展厅设计公司江苏seo哪家好
  • 莆田网站格在哪里做做网站需要租空间吗
  • 网站开发总结与未来展望外贸做那种网站
  • 抚顺网站建设技术员招聘怎么样上传网站资料
  • wordpress视频站代码接go语言网站开发
  • html网站模板免费下载申请做网站、论坛版主
  • 建设银行中国网站重庆餐饮网站设计
  • 浪漫做爰网站wordpress再安装
  • 国际网站卖东西怎么做公司网站包括哪些内容
  • 汕头企业网站建站模板vf建设银行网站
  • 建网站与建网页的区别网站seo优化查询
  • win10虚拟机做网站wordpress换主题影响seo吗
  • 丹阳网络营销长春网站建设seo
  • 响应式外贸网站价格室内设计平面布置图
  • 推广seo网站建行手机app下载
  • 展示型网站设计公司wordpress内容页文件名
  • 免费全能网站空间怎么接做网站的任务
  • 网站头条怎么做如何写一个wordpress主题
  • 山东网站建设SEO优化制作设计公司html网页制作模板免费
  • 注册网站给谁交钱遮罩层怎么做网页