python-3.x - Python shapely:如何仅对形状的内部区域进行三角测量
问题描述
我想使用 shapely 将此形状转换为三角形网格,以便稍后在 unity3d 中用作 3d 表面,但结果似乎并不好,因为三角形网格覆盖了此形状之外的区域。
def get_complex_shape(nb_points = 10):
nb_shifts = 2
nb_lines = 0
shift_parameter = 2
r = 1
xy = get_points(0, 0, r, nb_points)
xy = np.array(xy)
shifts_indices = np.random.randint(0, nb_points ,nb_shifts) # choose random points
if(nb_shifts > 0):
xy[shifts_indices] = get_shifted_points(shifts_indices, nb_points, r + shift_parameter, 0, 0)
xy = np.append(xy, [xy[0]], axis = 0) # close the circle
x = xy[:,0]
y = xy[:,1]
if(nb_lines < 1): # normal circles
tck, u = interpolate.splprep([x, y], s=0)
unew = np.arange(0, 1.01, 0.01) # from 0 to 1.01 with step 0.01 [the number of points]
out = interpolate.splev(unew, tck) # a circle of 101 points
out = np.array(out).T
else: # lines and curves
out = new_add_random_lines(xy, nb_lines)
return out
enter code here
data = get_complex_shape(8)
points = MultiPoint(data)
union_points = cascaded_union(points)
triangles = triangulate(union_points)
此链接用于图片: 蓝色图片是我想要将其转换为三角形网格的多边形,右侧图片是覆盖超过多边形内部区域的三角形网格。我怎么能只覆盖多边形的内部区域?
解决方案
推荐阅读
- python - Kivy 运行声音界面和 GUI
- python-3.x - 在模块级别缓存值和单元测试
- java - 原因:java.util.ConcurrentModificationException: null with Preremove annotation
- python - 在抓取数据时修复第一个 POST 请求上的错误 408
- html - 调整大小时如何防止使用绝对位置更改项目的位置
- python - 在 Python 3.8 中,如何从 JsonStore 文件中加载图像列表?
- php - 符合 url 令牌的 PHP 发送表单
- php - php 页面无法识别另一个文件中包含的函数
- javascript - JSDoc 泛型中什么时候应该有一个点?
- angular - 如何处理 Angular 布局及其原因(优点/缺点)