The Cross Product is a property of vectors. The cross product takes two vectors and returns a third, which is perpendicular, or orthogonal, to the passed vectors. This vector is referred to as the normal vector, which normally is corrected to have a total magnitude of one in mathematics.
Definition
If vectors u and v are crossed ("u cross v"), the magnitude of the normal vector is equal to |u||v|sin(θ). Thus,
|u × v| = |u||v||sin(θ)||n| |u × v| = |u||v||sin(θ)|
In other applications, this magnitude has been found to be equal to the area of the parallelogram whose vertecies are at 0, u, u+v, and v.
In addition,
u × 0 = 0 u × v = -(v × u) (ru) × (sv) = (rs) u × v (where r and s are scalars)
General Application of the Cross Product
It is common practice in mathematics to write vectors as sums of the unit vectors, i, j, and k. These each have a magnitude of one and, from the origin, move precisely 1 unit on the x, y, and z axes respectively.
Say, then, that we have two vectors, u and v.
u = <u1,u2,u3> v = <v1,v2,v3>
We can rewrite these vectors in terms of i, j, and k.
u = u1i + u2j + u3k v = v1i + v2j + v3k
We can then "multiply" them in an algebraic manner.
u × v = (u1v1)i × i + (u1v2)i × j + (u1v3)i × k + (u2v1)j × i + (u2v2)j × j + (u2v3)j × k + (u3v1)k × i + (u3v2)k × j + (u3v3)k × k
We can remove immediately any terms where the vector is crossing itself. The angle between two parallel vectors, a and b, is 0, thus a × b = |a||b|sin(0)|n| = 0 . So, the above statement simplifies to
u × v = (u1v2)i × j + (u1v3)i × k + (u2v1)j × i + (u2v3)j × k + (u3v1)k × i + (u3v2)k × j
Because the cross product reflects the normal vector, the following hold:
i × j = -(j × i) = k j × k = -(k × j) = i k × i = -(i × k) = j
Then, we can simplify our equation further:
u × v = (u1v2)k + (u1v3)(-j) + (u2v1)(-k) + (u2v3)i + (u3v1)j + (u3v2)(-i) = (u2v3-u3v2)i + (u3v1-u1v3)j + (u1v2-u2v1)k = (u2v3-u3v2)i - (u1v3-u3v1)j + (u1v2-u2v1)k (u-components are in order)
This describes the direction of the normal vector to the vectors u and v. This sum can be expressed in matrices
= |
|
i - |
|
j + |
|
k |
= |
|
The Cross Product in GraalScript
The cross product of two vector arrays in Graal can be obtained through the vectorcross(u,v) function. It's return value is a vector, w1i + w2j + w3k, where the vector w is calculated from the determinant of the above matrix.