"""
@file: new
@time: 2024-07-25 22:53
@author: Ke Li
@desc:
"""
from shapely import LineString
def get_approximate_line_shape(self, line_shape, start_theta, robot_shape, orientation, orientation_type):
"""
基于离散polygon取union的方式获得锁区的近似体
:param line_shape:
:param start_theta:
:param robot_shape:
:param orientation
:param orientation_type
:return:
"""
moving_polygons = []
# 设置一个微小的膨胀区
base_polygon = copy.deepcopy(robot_shape).buffer(distance=self.config.buffer_traffic_locks_margin,
cap_style='flat')
if orientation_type == "GLOBAL":
base_polygon = rotate(base_polygon, angle=orientation, use_radians=True)
elif orientation_type == "TANGENTIAL":
pass
else:
raise Exception("Orientation Type Error:{}---Supported Types: GLOBAL, TANGENTIAL".format(orientation_type))
for i in range(len(line_shape.coords) - 1):
start = line_shape.coords[i]
end = line_shape.coords[i + 1]
start_polygon = copy.deepcopy(base_polygon)
if orientation_type == "TANGENTIAL":
# 对于TANGENTIAL类型,在移动中需要修改其对应角度
# 先计算线段角度
line_theta = math.atan2(end[1] - start[1], end[0] - start[0])
if i == 0 and np.round(
min(abs(line_theta - start_theta), 2 * np.pi - abs(line_theta - start_theta)), 2) == 3.14:
# 在起点时,比对一下start_theta是否和该线的方向相反,若相反,angle需要取反向
line_theta += np.pi
start_polygon = rotate(start_polygon, origin=[0, 0], angle=line_theta, use_radians=True)
moving_polygon = translate(start_polygon, xoff=start[0], yoff=start[1])
# 平移多边形
translated_polygon = translate(start_polygon, xoff=end[0], yoff=end[1])
# 创建连接原始多边形和平移多边形的侧面
sides = []
original_coords = list(moving_polygon.exterior.coords)
translated_coords = list(translated_polygon.exterior.coords)
for i in range(len(original_coords) - 1):
side = shapely.geometry.Polygon(
[original_coords[i], original_coords[i + 1], translated_coords[i + 1], translated_coords[i]])
sides.append(side)
moving_polygons.append(unary_union(sides + [moving_polygon, translated_polygon]))
# # 获取平滑部分
# smooth_line_shape = self.get_curve_global_oriented_line_shape(line_shape=line_shape,
# orientation=0,
# robot_shape=copy.deepcopy(robot.shape_base))
union_line_shape = unary_union(moving_polygons)
# print("region:", list(union_line_shape.exterior.coords))
return union_line_shape
呆呆小雅
- 粉丝: 1790
- 资源: 116
最新资源
- 新学期幼儿园班会家长会介绍模板.pptx
- STM32F401RCT6-RTOS-EXAMPLE12.rar
- 计算机网络技术978-7-115-48545-8习题答案
- 基于python的NBA球员数据可视化分析源码+答辩PPT(高分项目)
- service暴露应用
- 构建HTML/CSS/JavaScript跨年倒计时网页以增强节日互动性
- Python基础练习之词频统计
- linux常用命令大全常用.txt
- Python跨年基础练习之手机通讯录
- linux常用命令大全常用.txt
- linux常用命令大全常用.txt
- 基于python的NBA球员数据可视化分析源码+文档PPT
- 写频软件MD-760 v3.2.1(最新)
- Python跨年基础练习之新年成语接龙小游戏
- 云兴私有云大华存储部署
- API Spec 14A-2024 Subsurface Safety Valve and Annular Safety Valve Equipment.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈