Last active
July 7, 2019 12:14
-
-
Save Citymonstret/abae98becd0a0d263850db711ac3ebc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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