本文整理汇总了Python中scipy.spatial.Delaunay.append方法的典型用法代码示例。如果您正苦于以下问题:Python Delaunay.append方法的具体用法?Python Delaunay.append怎么用?Python Delaunay.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.spatial.Delaunay
的用法示例。
在下文中一共展示了Delaunay.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_object
# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import append [as 别名]
def get_object(self):
points = list(self.points) # Shallow Copy
tris = Delaunay([p.to_list()[:2] for p in points], qhull_options="Qt")
tris = [[t[0], t[1], t[2]] for t in tris.simplices]
tris = [list(reversed(l)) for l in tris]
edge_count = {}
for tri in tris:
for i in range(3):
a = tri[i]
b = tri[(i + 1) % 3]
key = (a, b)
edge = edge_count.get(key)
if edge == None:
key = (b, a)
edge = edge_count.get(key)
if edge == None:
edge_count[key] = 1
else:
edge_count[key] = edge_count[key] + 1
edges = []
for key, value in edge_count.iteritems():
if value == 1:
edges.append(key[0])
edges.append(key[1])
edges = list(set(edges))
avg_point = reduce(lambda x, i: x + points[i], edges, Vec3())
avg_point /= len(edges)
avg_point.z = 0
def get_angle(a):
x = a.x - avg_point.x
y = a.y - avg_point.y
return atan2(y, x)
def sort_fun(a, b):
return 1 if get_angle(points[a]) < get_angle(points[b]) else -1
edges.sort(sort_fun)
new_points = []
for p in edges:
np = points[p].copy()
np.z = 0
new_points.append(np)
for i in range(len(new_points)):
t1 = [edges[i], len(points) + i, len(points) + ((i + 1) % len(new_points))]
t2 = [
edges[i],
len(points) + ((i + 1) % len(new_points)),
edges[(i + 1) % len(new_points)],
]
tris.append(t1)
tris.append(t2)
points += new_points
points.append(avg_point)
for i in range(len(new_points)):
tris.append(
list(
reversed(
[
len(points) - 1,
len(points) - 1 - len(new_points) + i,
len(points)
- 1
- len(new_points)
+ ((i + 1) % len(new_points)),
]
)
)
)
# return union() ( [translate( points[v].to_list() ) ( linear_extrude( 10 ) ( text( str(i), size=100, valign="center", halign="center" ) ) ) for i, v in enumerate( edges ) ])
return polyhedron(points=[p.to_list() for p in points], faces=tris)