首页 > 解决方案 > 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-3.xunity3dmesh

解决方案


推荐阅读