如何使用python从给定坐标创建3D曲面? [英] How to create a 3D surface from given coordinates with python?

查看:453
本文介绍了如何使用python从给定坐标创建3D曲面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的高度有些离散坐标,我需要创建一个光滑的表面,并将继续使用它。我需要该表面上所有坐标的高度。我当时正在考虑使用3D样条,但在应用类似问题中建议的方法时遇到了麻烦。我不是一个经验丰富的程序员,所以我可能会发现任何建议都是有帮助的。如果我可能要问的问题与之前已经讨论过的非常相似,请原谅我。我正在使用Python 3.6。

I have some discrete coordinates with their heights and I need to create a smooth surface which I will continue to use. I need to have heights for all the coordinates in that surface. I was considering using a 3D spline but I am having trouble applying the methods suggested in comparable kind of questions. I am not an experienced programmer so I would probably find any suggestions helpful. Please forgive me if I may asked something very similar to what was already discussed before. I am using Python 3.6.

EDIT

我列出了一个很小的列表(类似于我的列表)。

I made a tiny list (similar to what I have).

Z=[]
Z.append([20.2, 20.1, 35])
Z.append([20.1, 24.5, 36])
Z.append([21.0, 23.2, 33])
Z.append([22.3, 20.0, 34])
Z.append([22.3, 19.5, 28])
Z.append([20.1, 19.5, 27])
Z.append([20.1, 24.6, 31])
Z.append([22.3, 24.6, 32])

此处的第一个数字代表经度,第二个数字代表经度,第三个数字代表经度高度。我需要制作一个表面(不一定要绘制它),其中将包含有关此矩形之间所有坐标的信息。

The first number here represents longitude, the second - latitude and the third - altitude. I need to make a "surface" (not necessarily to plot it) which would contain the information about all the coordinates in between this rectangle.

我相信这听起来不清楚但是可能的问题是我不知道我要查找的确切结构或数据类型。

I believe this could sound unclear but maybie the problem is that I do not know the exact structure or the type of data I am looking for.

推荐答案

一种可能性是使用来自scipy的方法 griddata

One possibility is to use method griddata from scipy.

这是一个小示例,如何对数据使用近邻插值方法:

Here is small example how to use neareast neighbour interpolation method with your data:

import numpy as np
from scipy.interpolate import griddata
# --------------------
Z=[]
Z.append([20.2, 20.1, 35])
Z.append([20.1, 24.5, 36])
Z.append([21.0, 23.2, 33])
Z.append([22.3, 20.0, 34])
Z.append([22.3, 19.5, 28])
Z.append([20.1, 19.5, 27])
Z.append([20.1, 24.6, 31])
Z.append([22.3, 24.6, 32])
# ---------------------------
xin=np.array(Z)[:,0];
yin=np.array(Z)[:,1];
zin=np.array(Z)[:,2];
# ----------------------------
xout=np.linspace(20.,23.,10);
yout=np.linspace(19.,25.,10);
xout,yout = np.meshgrid(xout,yout);
# ----------------------------
zout=griddata((xin,yin),zin,(xout,yout),'nearest');
# -----------------------------
from pylab import pcolormesh,show
pcolormesh(xout,yout,zout);show();

这篇关于如何使用python从给定坐标创建3D曲面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆