我具有一堆点的坐标,并想在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.
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] 删除。
我来说两句