Last active
May 24, 2017 12:07
-
-
Save hpohlmeyer/f04336b50e368130665be2f5ac0adc3b to your computer and use it in GitHub Desktop.
2:1 isometric grid calculator
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
/** | |
* Calculate a 2:1 iso grid for specific sizes. | |
* | |
* @author Henning Pohlmeyer | |
* | |
* @param {number} smallestValue The smalles value to use in the grid. | |
* @return {object} The grid spacing value and rotate and | |
* shear values for each plane. | |
*/ | |
function calculateIsoGrid(smallestValue) { | |
const a = smallestValue || 1; | |
const b = a * 2; | |
const c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); | |
const radians = Math.atan(a/b); | |
const degree = radians * 180 / Math.PI; | |
return { | |
gridSpacing: `${c}px`, | |
topPlane: { | |
rotate: `${degree}°`, | |
shear: `${90 - 2 * degree}°`, | |
}, | |
rightPlane: { | |
rotate: `${degree}°`, | |
shear: `${-degree}°`, | |
}, | |
leftPlane: { | |
rotate: `${-degree}°`, | |
shear: `${degree}°`, | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment