Skip to content

Instantly share code, notes, and snippets.

@Citymonstret
Last active July 7, 2019 12:14
Show Gist options
  • Select an option

  • Save Citymonstret/abae98becd0a0d263850db711ac3ebc0 to your computer and use it in GitHub Desktop.

Select an option

Save Citymonstret/abae98becd0a0d263850db711ac3ebc0 to your computer and use it in GitHub Desktop.
function leviCivita(i, j, k) {
let d1 = i - j;
let d2 = j - k;
let d3 = k - i;
return (d1 * d2 * d3) / 2;
}
function cross(v1, v2) {
if (v1.length !== v2.length !== 3) {
return new Error("Only 3D vectors are supported");
}
let result = [0, 0, 0];
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
for (var k = 0; k < 3; k++) {
result[i] += leviCivita(i, j, k) * v1[j] * v2[k];
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment