如何在 3 维空间中绘制一条线

问题描述 投票:0回答:1

我有两个 3D 点,例如 a = (100, 100, 10) 和 b = (0, 100, 60),并且想要通过这些点拟合一条线。 我知道,3D 直线方程可以有不同的形状:

矢量形式:

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

参数形式:

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

但是我在为数值函数获取正确形状的数据时遇到问题。

python matplotlib numerical-methods matplotlib-3d vector-space
1个回答
1
投票

以下代码应该可以工作

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()

这里

ax.plot3D()
绘制了一条用直线连接点
(x[i], y[i], z[i])
的曲线。

© www.soinside.com 2019 - 2024. All rights reserved.