The cross product of two three-dimensional vectors
b is the unique vector
c such that:
cis orthogonal to both
The magnitude of
cis equal to the area of the parallelogram formed by
The directions of
c, in that order, follow the right-hand rule.
There are a few equivalent formulas for cross product, but one is as follows:
where i, j, and k are the unit vectors in the first, second, and third dimensions.
Given two 3D vectors, write a full program or function to find their cross product. Builtins that specifically calculate the cross product are disallowed.
Two arrays of three real numbers each. If your language doesn't have arrays, the numbers still must be grouped into threes. Both vectors will have magnitude <216. Note that the cross product is noncommutative (
b = -(
a)), so you should have a way to specify order.
Their cross product, in a reasonable format, with each component accurate to four significant figures or 10-4, whichever is looser. Scientific notation is optional.
[3, 1, 4], [1, 5, 9] [-11, -23, 14] [5, 0, -3], [-3, -2, -8] [-6, 49, -10] [0.95972, 0.25833, 0.22140],[0.93507, -0.80917, -0.99177] [-0.077054, 1.158846, -1.018133] [1024.28, -2316.39, 2567.14], [-2290.77, 1941.87, 712.09] [-6.6345e+06, -6.6101e+06, -3.3173e+06]
This is code-golf, so the shortest solution in bytes wins.
Maltysen posted a similar challenge, but the response was poor and the question wasn't edited.