【发布时间】:2022-01-20 09:04:12
【问题描述】:
我试图在第一步中找到一种通过已知向量拟合直线的方法。 第二步应该是找到这条线和所示平面之间的交点。 我要拟合一条线的向量用黑色椭圆标记,并在代码中命名为vector_3。
目标是在蓝色矢量路径围绕 x 或 y 轴旋转时调整 vector_3 的长度,以获得始终在平面处结束的新矢量。
这是代码(简化为现在相关的内容)和结果图:
import numpy as np
import matplotlib.pyplot as plt
# Import 6D-Pose
translation_6D_pose = np.array([100, 0, 0, 1])
rotation_6D_pose = np.array([0, 0, 0])
# Definition of vectors
origin = np.array([0, 0, 0])
vector_1 = np.array([0, 100, 10, 1])
vector_2 = np.array([-100, 0, 50, 1])
vector_3 = np.array([0, 100, 0, 1])
vector_4 = np.array([0, 0, 60, 1])
X, Y, Z = origin
U, V, W, _ = translation_6D_pose
A, B, C, _ = vector_1
D, E, F, _ = vector_2
G, H, I, _ = vector_3
J, K, L, _ = vector_4
# Plot figure:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.set_xlim([-50, 200])
ax.set_ylim([-50, 200])
ax.set_zlim([-50, 200])
# Make plane:
xx, yy = np.meshgrid(range(-100, 100), range(0, 200))
z = xx*0 + 60
ax.plot_surface(xx, yy, z, alpha=0.2)
# Plot vectors:
ax.quiver(X, Y, Z, U, V, W)
ax.quiver(U, V, W, A, B, C)
ax.quiver(U+A, V+B, W+C, D, E, F)
ax.quiver(X, Y, Z, G, H, I, color="r")
ax.quiver(G, H, I, J, K, L, color="r")
plt.show()
【问题讨论】:
标签: python numpy matplotlib vector 3d