简体   繁体   English

将定义 3D 表面的 x、y、z 坐标插入到任意平面

[英]Interpolate x,y,z co-ordinates defining a 3D surface to arbitrary plane

Suppose I have a set of x,y,z co-ordinates defining the surface of a 3D structure:假设我有一组定义 3D 结构表面的 x,y,z 坐标:

points = [[x0,y0,z0],
          [x1,y1,z1],
          [xn,yn,zn]]

How do you recommend that I obtain a list of 2D points defining the perimeter of the structure for a given slice?您如何建议我获得定义给定切片结构周长的二维点列表?

For example, I might want the x,z points of my structure at y = 1.5, but assume no points are actually defined on that plane, so I need to linearly interpolate.例如,我可能需要 y = 1.5 处的结构的 x、z 点,但假设该平面上实际上没有定义任何点,因此我需要进行线性插值。

I feel like scipy.interpolate.griddata holds the answer, but I can't seem to get my head around how to apply it in this case.我觉得 scipy.interpolate.griddata 拥有答案,但我似乎无法理解如何在这种情况下应用它。 Any help would be greatly appreciated.任何帮助将不胜感激。

You can achieve this with scipy.ndimage.map_coordinates :您可以使用scipy.ndimage.map_coordinates实现此scipy.ndimage.map_coordinates

from scipy.ndimage import map_coordinates
import numpy as np
arr = np.arange(25, dtype=float).reshape((5, 5))
arr
Out[39]: 
array([[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.],
       [10., 11., 12., 13., 14.],
       [15., 16., 17., 18., 19.],
       [20., 21., 22., 23., 24.]])

map_coordinates(arr, (np.arange(5), [1.5]*5))
Out[40]: array([ 1.55357143,  6.55357143, 11.55357143, 16.55357143, 21.55357143])

This requires passing coordinates explicitly, I'm not sure how to leverage numpy indexing with map_coordinates to get an entire column, but this is at least a solution.这需要显式传递坐标,我不确定如何利用带有 map_coordinates 的 numpy 索引来获取整个列,但这至少是一个解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM