如何在python中的常规3D网格上找到相邻的线

阿里_d

我具有一堆点的坐标,并想在python包中从中创建表面。我想先安排数据,然后再将其导入包中。点来自常规网格。首先,我基于点的位置创建线。在这一步中,我仅定义创建点的线号。我的输入数据是:

coord = np.array(
    [[0., 0., 2.], [0., 1., 3.], [0., 2., 2.], [1., 0., 1.], [1., 1., 3.], 
     [1., 2., 1.], [2., 0., 1.], [2., 1., 1.], [3., 0., 1.], [4., 0., 1.]])

下图显示了网格点的数量(灰色)和线的数量(蓝色和红色)。

格

通过字典对线进行建模,其中的键是线号,值是具有起点和终点数字的元组:

In [906]: blue_line
Out[906]: {1: (1, 2), 2: (2, 3), 3: (4, 5), 4: (5, 6), 5: (7, 8)}

In [907]: red_line
Out[907]: 
{6: (1, 4),
 7: (2, 5),
 8: (3, 6),
 9: (4, 7),
 10: (5, 8),
 11: (7, 9),
 12: (9, 10)}

To learn more about how the lines are generated, check out this thread. The lines that are used to create the surfaces are stored in a list:

surfaces = [(1, 6, 3, 7), (2, 7, 4, 8), (3, 9, 5, 10)]

As the last step, I want to find the number of lines which are not used in creating the surfaces or are used but are closer than a limit the the dashed line in the figure above. Again, I have the coordinate of the two points creating that dashed line:

coord_dash = [(2., 2., 2.), (5., 0., 1.)]
adjacency_threshold = 2

I want to have these adjacent lines as another list (shown by a red arrow in the figure):

adjacent_lines = [4, 10, 5, 11, 12]

I have only this rough idea and do not know how to code it in Python. I can only create line numbers and surfaces and need help to find those close lines.

Tonechas

Determining what lines have not been used is straightforward (NumPy's setdiff1d comes in handy for this task):

In [924]: all_line = {**blue_line, **red_line}

In [925]: lines = list(all_line.keys())

In [926]: lines
Out[926]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

In [927]: used_lines = np.ravel(surfaces)

In [928]: used_lines
Out[928]: array([ 1,  6,  3,  7,  2,  7,  4,  8,  3,  9,  5, 10])

In [929]: unused_lines = np.setdiff1d(lines, used_lines)

In [930]: unused_lines
Out[930]: array([11, 12])

相邻的行可以通过使用NumPy获得linalg.norm

In [954]: midpoints
Out[954]: 
{1: array([0. , 0.5, 2.5]),
 2: array([0. , 1.5, 2.5]),
 3: array([1. , 0.5, 2. ]),
 4: array([1. , 1.5, 2. ]),
 5: array([2. , 0.5, 1. ]),
 6: array([0.5, 0. , 1.5]),
 7: array([0.5, 1. , 3. ]),
 8: array([0.5, 2. , 1.5]),
 9: array([1.5, 0. , 1. ]),
 10: array([1.5, 1. , 2. ]),
 11: array([2.5, 0. , 1. ]),
 12: array([3.5, 0. , 1. ])}

In [955]: mid_dash = np.array(coord_dash).mean(axis=0)

In [956]: mid_dash
Out[956]: array([3.5, 1. , 1.5])

In [957]: adjacent_lines = []
     ...: for idx, point in midpoints.items():
     ...:     if np.linalg.norm(point - mid_dash) < adjacency_threshold:
     ...:         adjacent_lines.append(idx)

In [958]: adjacent_lines
Out[958]: [5, 11, 12]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在3D网格上找到连接的三角形

来自分类Dev

如何在QML场景上绘制3D线?

来自分类Dev

如何在Kivy中更改3D网格的颜色?

来自分类Dev

3d网格中的转发(绘图)线

来自分类Dev

如何在边界内在3D轴上绘制2D Voronoi网格?

来自分类Dev

Python在3D散点图中用线连接相邻点

来自分类Dev

如何在Python上制作3D图形动画

来自分类Dev

如何在Python中将3D数据绘制为2D网格颜色图?

来自分类Dev

如何在three.js中从BufferGeometry绘制2D/3D网格

来自分类Dev

如何在Python中以数字方式计算复杂3D形状上的体积积分?

来自分类Dev

如何在八度/ Matlab中绘制3D线

来自分类Dev

如何在JavaFX 3D中制作矢量图形样式线?

来自分类Dev

如何在OpenGL中为3D模型(网格)设置动画?

来自分类Dev

如何在3D图中脱离网格

来自分类Dev

如何在python中旋转3D文本?

来自分类Dev

如何在python中顺序填充3d矩阵?

来自分类Dev

如何在python中绘制3d图形

来自分类Dev

如何在数据集中找到与所需线最近的相邻线?

来自分类Dev

如何围绕Three.js工作空间中的随机3d对象/网格/ 3d线的轴线旋转网格组?

来自分类Dev

在Julia中的常规2D网格上绘制值

来自分类Dev

如何找到垂直于线中点的点的3D坐标

来自分类Dev

熊猫:如何在pd.DataFrame.plot()中的x轴上显示较小的网格线

来自分类Dev

如何在3D三角形的给定点(x,z)上找到y?

来自分类Dev

如何逐步合并3D网格

来自分类Dev

如何在d3线中创建折弯

来自分类Dev

如何在序列中查找相邻对,python

来自分类Dev

如何在OpenGL中的3D对象上应用纹理

来自分类Dev

如何在Matlab中的3D图像上实现gabor滤镜

来自分类Dev

如何在JavaFX中的3D场景上覆盖GUI?

Related 相关文章

热门标签

归档