python - 如何在 Python 中直接在代码中计算叉积(用于以后的 3D-Plot)?
问题描述
*# 我在脚本下面的解决方法不是很优雅,它是先手动计算叉积(数组格式),然后将数据手动输入到上面的代码(一种 6-tupel-vector 格式)到行cross_AxB 和 cross_BxA 以获得 3D 图。
我想有一种方法可以直接在代码中以可绘图格式计算叉积 np.cross,就像其他操作/函数(如(*、/、np.pi 等)一样)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
#crossproduct for initial calculation (print below) & then manual input into below cross_AxB and cross_BxA
x = np.array([[0,0,0], [1,2,3]])
y = np.array([[0,0,0], [-3,5,7]])
vector_A = ([0,0,0,1,2,3])
vector_B = ([0,0,0,-3,5,7])
cross_AxB = ([0, 0, 0, -1, -16, 11])
cross_BxA = ([0, 0, 0, 1, 16, -11])
vectors = np.array([vector_A, vector_B, cross_AxB, cross_BxA])
X, Y, Z, U, V, W = zip(*vectors)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.quiver(X, Y, Z, U, V, W)
ax.set_xlim([-10, 10])
ax.set_ylim([-10, 10])
ax.set_zlim([-10, 10])
plt.draw()
print(np.cross(x,y))
print(np.cross(y,x))
解决方案
推荐阅读
- jquery - 如何在日期范围选择器 JQuery 插件中限制小时
- javascript - TypeError:无法读取未定义的属性“状态” - 呈现内容
- json - 如何在 Flutter 中解析列表中的列表?
- c# - 如何让游戏对象旋转并远离 Unity 中的 MouseClick 位置?
- java - Android Studio (Java) 未按顺序接收正确的 Button 值
- laravel - “已批准”状态后如何更新产品数量?
- apache-spark - 关于 Spark 分区的困境
- json - 如何在我不知道 name 属性的对象数组中执行 *ngFor?
- c++ - 如何在 wxwidgets 中进行多键输入?
- javascript - 我不明白设置日期方法在 JavaScript 中的工作原理