I want to calculate the cross product of x
and vector y
without numpy or any imports.
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.