Python 从由一串点定义的横截面在固定栅格上创建三维高程

Python 从由一串点定义的横截面在固定栅格上创建三维高程,python,polyline,terrain,Python,Polyline,Terrain,我试图在一个固定的网格上创建一个3D曲面,比如说1米或0.5米的间距,其中曲面是一个由多个点的横截面定义的通道。理想情况下,它应该是任意数量的点。例如,横截面,例如: PTS=[[0.0,10.0]、[3.0,9.0]、[30.0,8.5]、[33.0,8.0]、[35.0,7.8]、[37.0,8.0]、[40.0,8.5]、[67.0,9.0]、[70.0,10.0]] 此处渠道宽70 m,具有双梯形截面 我已尝试对此进行编码,但未能确定日期: 我想读取点,然后根据间距进行插值,以提供计算出

我试图在一个固定的网格上创建一个3D曲面,比如说1米或0.5米的间距,其中曲面是一个由多个点的横截面定义的通道。理想情况下,它应该是任意数量的点。例如,横截面,例如:

PTS=[[0.0,10.0]、[3.0,9.0]、[30.0,8.5]、[33.0,8.0]、[35.0,7.8]、[37.0,8.0]、[40.0,8.5]、[67.0,9.0]、[70.0,10.0]] 此处渠道宽70 m,具有双梯形截面

我已尝试对此进行编码,但未能确定日期:

我想读取点,然后根据间距进行插值,以提供计算出的高程(Z值)。这将填充X&Y域,从而提供三维地形的XYZ值

本示例旨在创建一条1500m长、70m宽的水道

代码:


设置计算域 当代码遍历X时,基本Z提供了一个倾斜的河床,然后定义的横截面在Y的范围内创建Z

理想情况下,这也可以沿多段线应用,而不是仅在x方向应用。这样,通道可以沿着曲线生成,例如S形弯曲

我希望有人对如何解决这个问题有一些聪明的想法。。。多谢各位

有人提到scipy可能会在这里提供帮助。。。。我将尝试理解这一点,创建一个函数在点之间插值:

从scipy.interpolate导入interp1d

x=np.linspace(0,10,10)

y=np.exp(-x/3.0)

f=1d(x,y)

f2=1d(x,y,kind='cubic')

xnew=np.linspace(0,10,40)

将matplotlib.pyplot作为plt导入

平面图(x,y,'o',xnew,f(xnew),'-',xnew,f2(xnew),'-'))

plt.图例(['data','linear','cubic'],loc='best')

plt.show()


通过最初将第三维设置为零,可以从一开始就在三维中处理通道纵断面。通过这种方式,您将能够沿曲线旋转和平移轮廓。例如:

#The DEM
DEM = numpy.array((height,width)); #...because a row corresponds to the y dimension
#Channel center line
cCurve = [[0.0,0.0],[0.0,1.0],[1.0,2.0]] #A channel going north and then turning North-East
#Channel profile. It is better if you express this in relative coordinates to the center line. In this case, the points left to the center line would have negative X values and the points to the right would have positive X values. 
PTS = [[0.0,0.0,10.0],[3.0,0.0,9.0],[30.0,0.0,8.5],[33.0,0.0,8.0],[35.0,0.0,7.8],[37.0,0.0,8.0],[40.0,0.0,8.5],[67.0,0.0,9.0],[70.0,0.0,10.0]];
#
for (aCenterLinePoint in range(0,len(cCurve)-1)):
     #Translate the channel profile to the current location of the center line
     translatedPTS = Translate(PTS,cCurve[aCenterLinePoint]);
     #Rotate the channel profile, along the Z axis to an angle that is defined by the current center line point and the next center line point
     rotatedTranslatedPTS = Rotate(rotatedPTS,getAngle(cCurve[aCenterLinePoint],cCurve[aCenterLinePoint+1]))
     # "Carve" the DEM with the Channel profile. You can apply interpolation here if you like
     for (aChannelPoint in rotatedTranslatedPTS):
         DEM[aChannelPoint[1], aChannelPoint[0]] = aChannelPoint[2]; #Please note the reversal of the X,Y coordinates to account for the classical array indexing!
我希望上面的片段能传达这样的想法:-)。缺少的内容以及您必须根据您的问题进行计算的内容包括:

1) “像素大小”,换句话说,您的河道剖面以米表示,但在DEM中,您正在使用矩阵中的索引(基本上)。需要建立一个简单的线性变换,以便您可以确定“多少像素”-距离中心线20米”

2) Translate()和Rotate()函数。任何简单的向量数学都可以。请注意,如果以0,0,0表示频道配置文件,则旋转将是非常简单的表达式。有关更多信息,请参见此处:

3) getAngle()函数是一个简单的atan2(vectorA,vectorB)。(例如:)。请注意,在这种情况下,您将围绕Z轴旋转,Z轴是DEM的“突出部分”

4) DEM与真实世界的方向。在上面的例子中,我们从0.0开始,然后向南移动,然后向东南移动,因为矩阵中的索引会从上到下增加


希望这有点帮助。您是在处理CFD问题,还是只是为了可视化?

我正在尝试创建一个通用的通道生成器,以便创建自由开源软件ANUGA a 2D浅水波eq解算器所使用的地形。所以不,这不是一个简单的想象。这是一个真实的地形模型,将由ANUGA用于确定流量behviour。我想生成一系列标准化频道,如梯形、双梯形等。我明白,我希望上述内容毕竟有所帮助。
#The DEM
DEM = numpy.array((height,width)); #...because a row corresponds to the y dimension
#Channel center line
cCurve = [[0.0,0.0],[0.0,1.0],[1.0,2.0]] #A channel going north and then turning North-East
#Channel profile. It is better if you express this in relative coordinates to the center line. In this case, the points left to the center line would have negative X values and the points to the right would have positive X values. 
PTS = [[0.0,0.0,10.0],[3.0,0.0,9.0],[30.0,0.0,8.5],[33.0,0.0,8.0],[35.0,0.0,7.8],[37.0,0.0,8.0],[40.0,0.0,8.5],[67.0,0.0,9.0],[70.0,0.0,10.0]];
#
for (aCenterLinePoint in range(0,len(cCurve)-1)):
     #Translate the channel profile to the current location of the center line
     translatedPTS = Translate(PTS,cCurve[aCenterLinePoint]);
     #Rotate the channel profile, along the Z axis to an angle that is defined by the current center line point and the next center line point
     rotatedTranslatedPTS = Rotate(rotatedPTS,getAngle(cCurve[aCenterLinePoint],cCurve[aCenterLinePoint+1]))
     # "Carve" the DEM with the Channel profile. You can apply interpolation here if you like
     for (aChannelPoint in rotatedTranslatedPTS):
         DEM[aChannelPoint[1], aChannelPoint[0]] = aChannelPoint[2]; #Please note the reversal of the X,Y coordinates to account for the classical array indexing!