[英]Solving the crossproduct of two 3D vectors in homogenuous coordinates (x,y,z,w)
I want to calculate the cross product of x
and vector y
without numpy or any imports.我想在没有 numpy 或任何导入的情况下计算x
和向量y
的叉积。
x = Vector(1,2,1,0)
y = Vector(0,1,2,1)
but my result is always wrong.但我的结果总是错误的。 what am i missing here?我在这里想念什么?
def crossproduct(x, y):
final = Vector()
final.v[0] = y.v[1] * v.v[2] - x.v[2] * y.v[1]
final.v[1] = y.v[2] * v.v[3] - x.v[3] * y.v[2]
final.v[2] = y.v[3] * v.v[0] - x.v[0] * y.v[3]
final.v[3] = y.v[0] * v.v[1] - x.v[1] * y.v[0]
return final
Solving cross on a Vec4
(homogenuous) is the same as solving it as a Vec3
(Cartesian), since you're in 3 dimensions, no matter how you use the w
component.在Vec4
(同质)上求解交叉与将其作为Vec3
(笛卡尔)求解相同,因为无论您如何使用w
分量,您都处于 3 维中。
Check your cross formula, the one I usually use looks like this:检查您的交叉公式,我通常使用的公式如下所示:
crossX = vector1.Y * vector2.Z - vector2.Y * vector1.Z
crossY = -(vector1.X * vector2.Z - vector2.X * vector1.Z)
crossZ = vector1.X * vector2.Y - vector2.X * vector1.Y
crossW = 0.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.