Skip to content

Instantly share code, notes, and snippets.

@brookjordan
Created December 10, 2017 17:22
Show Gist options
  • Save brookjordan/3024d0dabb70cf921d34fdd53a6cce36 to your computer and use it in GitHub Desktop.
Save brookjordan/3024d0dabb70cf921d34fdd53a6cce36 to your computer and use it in GitHub Desktop.
Calculations for pentagon dimensions
class Pentagon {
static get SIDE_COUNT() { return 5; };
static get TOTAL_ANGLE() { return 180 * (Pentagon.SIDE_COUNT - 2); };
static get CORNER_ANGLE() { return Pentagon.TOTAL_ANGLE / Pentagon.SIDE_COUNT; };
static get SQRT_SIDES() { return Math.sqrt(Pentagon.SIDE_COUNT); };
constructor (from, value) {
if (isNaN(+from)) {
this[from] = value;
} else {
this.sideLength = from;
}
}
get height() { return Pentagon.height(this.sideLength); }
get diagonalLength() { return Pentagon.diagonalLength(this.sideLength); }
get perimeterLength() { return Pentagon.perimeterLength(this.sideLength); }
get area() { return Pentagon.area(this.sideLength); }
get outerRadius() { return Pentagon.outerRadius(this.sideLength); }
get innerRadius() { return Pentagon.innerRadius(this.sideLength); }
static sideLength(sideLength) {
return sideLength;
}
static area(sideLength) {
return (Math.pow(sideLength, 2) / 4) * Math.sqrt(10 * Pentagon.SQRT_SIDES + 25);
}
static height(sideLength) {
return sideLength * Math.sqrt(5 / 4 + Pentagon.SQRT_SIDES / 2);
}
static outerRadius(sideLength) {
return (sideLength / 10) * Math.sqrt(10 * Pentagon.SQRT_SIDES + 50);
}
static innerRadius(sideLength) {
return (sideLength / 10) * Math.sqrt(10 * Math.sqrt(5) + 25);
}
static diagonalLength(sideLength) {
return (sideLength / 2) * (1 + Pentagon.SQRT_SIDES);
}
static perimeterLength(sideLength) {
return sideLength * 5;
}
static sideLengthFromArea(area) {
return Math.sqrt((4 * area) / Math.sqrt(10 * Pentagon.SQRT_SIDES + 25));
}
static sideLengthFromHeight(height) {
return (2 * height) / Math.sqrt(5 + 2 * Pentagon.SQRT_SIDES);
}
static sideLengthFromOuterRadius(outerRadius) {
return outerRadius * Math.sqrt(10 / (5 + Pentagon.SQRT_SIDES));
}
static sideLengthFromInnerRadius(innerRadius) {
return 2 * innerRadius * Math.sqrt(5 - (2 * Pentagon.SQRT_SIDES));
}
static sideLengthFromDiagonalLength(diagonalLength) {
return (2 * diagonalLength) / (1 + Pentagon.SQRT_SIDES);
}
static sideLengthFromPerimeterLength(perimeter) {
return perimeter / Pentagon.SIDE_COUNT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment