python画点云_python scipy Delaunay绘制点云

编辑:同时绘制凸面外壳import numpy as np

from scipy.spatial import Delaunay

points = np.random.rand(30, 2) # 30 points in 2-d

tri = Delaunay(points)

# Make a list of line segments:

# edge_points = [ ((x1_1, y1_1), (x2_1, y2_1)),

# ((x1_2, y1_2), (x2_2, y2_2)),

# ... ]

edge_points = []

edges = set()

def add_edge(i, j):

"""Add a line between the i-th and j-th points, if not in the list already"""

if (i, j) in edges or (j, i) in edges:

# already added

return

edges.add( (i, j) )

edge_points.append(points[ [i, j] ])

# loop over triangles:

# ia, ib, ic = indices of corner points of the triangle

for ia, ib, ic in tri.vertices:

add_edge(ia, ib)

add_edge(ib, ic)

add_edge(ic, ia)

# plot it: the LineCollection is just a (maybe) faster way to plot lots of

# lines at once

import matplotlib.pyplot as plt

from matplotlib.collections import LineCollection

lines = LineCollection(edge_points)

plt.figure()

plt.title('Delaunay triangulation')

plt.gca().add_collection(lines)

plt.plot(points[:,0], points[:,1], 'o', hold=1)

plt.xlim(-1, 2)

plt.ylim(-1, 2)

# -- the same stuff for the convex hull

edges = set()

edge_points = []

for ia, ib in tri.convex_hull:

add_edge(ia, ib)

lines = LineCollection(edge_points)

plt.figure()

plt.title('Convex hull')

plt.gca().add_collection(lines)

plt.plot(points[:,0], points[:,1], 'o', hold=1)

plt.xlim(-1, 2)

plt.ylim(-1, 2)

plt.show()

请注意,仅仅使用scipy.spatial.Delaunay来计算复杂的船体可能是过分了,因为仅计算船体原则上可以比计算三角剖分更快。不幸的是,Scipy中还没有直接使用Qhull计算外壳的接口。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值