Skip to content

Instantly share code, notes, and snippets.

@hpohlmeyer
Last active May 24, 2017 12:07
Show Gist options
  • Save hpohlmeyer/f04336b50e368130665be2f5ac0adc3b to your computer and use it in GitHub Desktop.
Save hpohlmeyer/f04336b50e368130665be2f5ac0adc3b to your computer and use it in GitHub Desktop.
2:1 isometric grid calculator
/**
* 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