line_segment

Calculate the voxel coordinates of a straight line between the two given end points

Import packages

[1]:
import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import scipy

ps.visualization.set_mpl_style()
np.random.seed(10)

Apply generator function:

2D example

Create input points:

[2]:
X0 = [1, 200]
X1 = [100, 1]

_2dx = [X0[0], X1[0]]
_2dy = [X0[1], X1[1]]

plt.figure(figsize=[4, 4])
plt.plot(_2dx, _2dy, 'o', color='black');
../../../_images/examples_generators_howtos_line_segment_7_0.svg

Generate line segment:

[3]:
[_2dx, _2dy] = ps.generators.line_segment(X0=X0, X1=X1)

plt.figure(figsize=[4, 4])
plt.plot(_2dx, _2dy, 'o', color='black');
../../../_images/examples_generators_howtos_line_segment_9_0.svg

Create input points:

[4]:
X0 = [50, 10, 100]
X1 = [200, 100, 300]

_3dx = [X0[0], X1[0]]
_3dy = [X0[1], X1[1]]
_3dz = [X0[2], X1[2]]

fig = plt.figure(figsize=[4, 4])
ax = fig.add_subplot(111, projection='3d')
ax.scatter(_3dx, _3dy, _3dz, 'o', color='black');
../../../_images/examples_generators_howtos_line_segment_12_0.svg

Generate line segment:

[5]:
_3dx, _3dy, _3dz = ps.generators.line_segment(X0=X0, X1=X1)

fig = plt.figure(figsize=[4, 4])
ax = fig.add_subplot(111, projection='3d')
ax.scatter(_3dx, _3dy, _3dz, 'o', color='black');
../../../_images/examples_generators_howtos_line_segment_14_0.svg