I have two 3D-points, for example a = (100, 100, 10) and b = (0, 100, 60), and would like to fit a line through those points.
I know, the 3D line equation can have different shapes:
Vector-form:
JavaScript
x
2
1
(x,y,z)=(x0,y0,z0)+t(a,b,c)
2
Parameter-form:
JavaScript
1
4
1
x=x0+ta
2
y=y0+tb
3
z=z0+tc
4
But I have a problem getting the data in the right shape for a numerical function.
Advertisement
Answer
The following code should work
JavaScript
1
14
14
1
import matplotlib.pyplot as plt
2
3
fig = plt.figure()
4
ax = plt.axes(projection ='3d')
5
6
# defining coordinates for the 2 points.
7
x = np.array([100, 0])
8
y = np.array([100, 100])
9
z = np.array([10, 60])
10
11
# plotting
12
ax.plot3D(x, y, z)
13
plt.show()
14
Here the ax.plot3D()
plots a curve that joins the points (x[i], y[i], z[i])
with straight lines.