Created
April 7, 2019 05:21
-
-
Save singularitti/6908a9f7f9c4f917ae88dc69cbe2adf2 to your computer and use it in GitHub Desktop.
Meshgrid on 3D #JavaScript #array
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 meshgrid(xArray, yArray, zArray) { | |
| /* | |
| Here xArray, yArray, zArray should all be 1d arrays. | |
| Then it returns 3 fortran-style 3D arrays, that is, | |
| they are all column-major order: | |
| http://www.wikiwand.com/en/Row-_and_column-major_order. | |
| The returned xMesh, yMesh, and zMesh are all of shape | |
| [zNum, xNum, yNum]. | |
| */ | |
| let xNum = xArray.size; | |
| let yNum = yArray.size; | |
| let zNum = zArray.size; | |
| let xMesh = reshape(tile(xArray, [zNum, yNum]), [zNum, xNum, yNum]); | |
| let yMesh = reshape(tile(tile(yArray, [1, xNum]).transpose(1, 0), [zNum]), [zNum, xNum, yNum]); | |
| let zMesh = tile(zArray, [1, xNum, yNum]); | |
| return [xMesh, yMesh, zMesh]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment