0

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:

(x,y,z)=(x0,y0,z0)+t(a,b,c)

Parameter-form:

x=x0+ta
y=y0+tb
z=z0+tc

But I have a problem getting the data in the right shape for a numerical function.

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74

1 Answers1

1

The following code should work

import matplotlib.pyplot as plt

fig = plt.figure()
ax = plt.axes(projection ='3d')
 
# defining coordinates for the 2 points.
x = np.array([100, 0])
y = np.array([100, 100])
z = np.array([10, 60])
 
# plotting
ax.plot3D(x, y, z)
plt.show()

Here the ax.plot3D() plots a curve that joins the points (x[i], y[i], z[i]) with straight lines.

  • Thanks for your answer! But this is not exactly what I'm looking for. I want to have a linear function like it would be in 2D: y = mx + b but extended to 3 dimensional space. And this function should be defined by the two points I mentioned before. So, your answer shows a part of the function I need. – user_mechtronics_13 Dec 19 '21 at 10:19
  • 1
    A line segment between two points A, B is defined by the equation `P = A + t(B-A)`, where t is a number from 0 to 1. In your case A=(100,100,10) and B=(0,100,60). If P=(x,y,z), we get: `x=100-100t, y=100, z=10+50t`. Is this what you're looking for? – Gurkirat Singh Bajwa Dec 19 '21 at 10:39
  • yes that's what I was looking for, thank you! – user_mechtronics_13 Dec 20 '21 at 07:44