How can I calculate the cross product of two vectors without the use of programming libraries?
E.g given vectors a = (1, 2, 3) and b = (4, 5, 6)
a = (1, 2, 3)
b = (4, 5, 6)
I did it like this:
def cross_product(u,v): dim = len(u) s = [] for i in range(dim): if i == 0: j,k = 1,2 s.append(u[j]*v[k] - u[k]*v[j]) elif i == 1: j,k = 2,0 s.append(u[j]*v[k] - u[k]*v[j]) else: j,k = 0,1 s.append(u[j]*v[k] - u[k]*v[j]) return s