Skip to content

Instantly share code, notes, and snippets.

@singularitti
Created April 7, 2019 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singularitti/847a79f4d9e64915f74a46707c42cb43 to your computer and use it in GitHub Desktop.
Save singularitti/847a79f4d9e64915f74a46707c42cb43 to your computer and use it in GitHub Desktop.
Compute cross product of 2 3D arrays #JavaScript #math #array
function crossProduct(arr1, arr2) {
/*
Here arr1, arr2 are both 1D arrays.
*/
let u1 = arr1[0];
let u2 = arr1[1];
let u3 = arr1[2];
let v1 = arr2[0];
let v2 = arr2[1];
let v3 = arr2[2];
return [u2 * v3 - u3 * v2, u3 * v1 - u1 * v3, u1 * v2 - u2 * v1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment