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

查看:34
本文介绍了如何使用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.

编辑

我列了一个小清单(类似于我所拥有的).

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天全站免登陆