2016-04-11 43 views
0

私は4次元の点群を持っています。ここでは、雲の各点には位置と値(x、y、z、値)があります。さらに、私は3D点群の中に「特別な」点S0を持っています。私はthisの例を使って、S0と比較してクラウド内で最も近い10点を見つけました。さて、私は10の最も近い点とその値のそれぞれについて、数が少ない配列を持っています。どのようにしてこれらの10ポイントを補間して、ポイントS0で補間値を見つけることができますか?コード例を以下に示します。空間内の一点に3Dデータを補間する(Python 2.7)

import numpy as np 
import matplotlib.pyplot as plt 

numpoints = 20 
linexs = 320 
lineys = 40 
linezs = 60 
linexe = 20 
lineye = 20 
lineze = 0 

# Create vectors of points 
xpts = np.linspace(linexs, linexe, numpoints) 
ypts = np.linspace(lineys, lineye, numpoints) 
zpts = np.linspace(linezs, lineze, numpoints) 
lin = np.dstack((xpts,ypts,zpts)) 

# Image line of points 
fig = plt.figure() 
ax = fig.add_subplot(211, projection='3d') 
ax.set_xlim(0,365); ax.set_ylim(-85, 85); ax.set_zlim(0, 100) 
ax.plot_wireframe(xpts, ypts, zpts) 
ax.view_init(elev=12, azim=78) 

def randrange(n, vmin, vmax): 
    return (vmax - vmin)*np.random.rand(n) + vmin 

n = 10 
for n in range(21): 
    xs = randrange(n, 0, 350) 
    ys = randrange(n, -75, 75) 
    zs = randrange(n, 0, 100) 
    ax.scatter(xs, ys, zs) 
dat = np.dstack((xs,ys,zs)) 
ax.set_xlabel('X Label') 
ax.set_xlim(0,350) 
ax.set_ylabel('Y Label') 
ax.set_ylim(-75,75) 
ax.set_zlabel('Z Label') 
ax.set_zlim(0,100) 

ax = fig.add_subplot(212, projection='3d') 
ax.set_xlim(0,365); ax.set_ylim(-85, 85); ax.set_zlim(0, 100) 
ax.plot_wireframe(xpts,ypts,zpts) 
ax.view_init(elev=12, azim=78) 

plt.show() 
dist = [] 

# Calculate distance from first point to all other points in cloud 
for l in range(len(xpts)): 
    aaa = lin[0][0]-dat 
    dist.append(np.sqrt(aaa[0][l][0]**2+aaa[0][l][1]**2+aaa[0][l][2]**2)) 
full = np.dstack((dat,dist)) 
aaa = full[0][full[0][:,3].argsort()] 
print(aaa[0:10]) 
+0

あなたの実装はOKと思われます。あなたが数量を一つの点で補間することに興味があるならば。しかし、あなたが他の点でそれをしたいのであれば、それは非常に非効率的です。ネイバーに基づいて補間を行う方法はありますが、ネイバーパーティクルを使用してこれを行う理由を指定してください。 – Alejandro

+0

スクリプトを実行すると、パーティクルクラウドを介して線分が得られます。最終的に、線分が5点で構成されているとしましょう。線分の最初の点で、ポイントクラウドに最も近いN点を探したいと思います。次に、ポイントクラウドの最も近いN個の値を補間して、線分の最初の点の値を求めます。私は2番目のポイントのためにこれを繰り返します。 – AaronJPung

+0

編集:ポイントクラウドは、3D空間のデータセットに基づいています。私は、空間上のある点で値を見つけるのに最も良い方法は、関心のある点に最も近いデータ点を使うことです(例えば、線分の最初の点) – AaronJPung

答えて

2

基本的な例です。補間にはmeshgridが必要ではなく、、ここではA=x+y+zという例の関数を生成するためには、高速のufuncを作成する必要があります。

from scipy.interpolate import interpn 
import numpy as np 

#make up a regular 3d grid 
X=np.linspace(-5,5,11) 
Y=np.linspace(-5,5,11) 
Z=np.linspace(-5,5,11) 
xv,yv,zv = np.meshgrid(X,Y,Z) 

# make up a function 
# see http://docs.scipy.org/doc/numpy/reference/ufuncs.html 
A = np.add(xv,np.add(yv,zv)) 
#this one is easy enough for us to know what to expect at (.5,.5,.5) 

# usage : interpn(points, values, xi, method='linear', bounds_error=True, fill_value=nan) 
interpn((X,Y,Z),A,[0.5,0.5,0.5]) 

は出力:

array([ 1.5]) 

あなたが興味の点の配列を渡す場合、それはあなたが複数の回答を得られます。

関連する問題