Regular Dodecahedron

node v18.11.0
version: 1.1.2
endpointsharetweet
const constants = require('@runkit/apatryda/constants/1.0.1'); const katex = require('@runkit/apatryda/katex/1.0.0'); const _ = require('lodash'); const { φ } = constants;
class RegularDodecahedron { constructor(scale = 1, flat = false, mirror = false) { Object.assign(this, { flat, mirror, scale, }); this.initVertices(); } initVertices() { this.vertices = [ ..._ .times(2, i => Math.pow(-1, i) * this.scale) .flatMap(x => _ .times(2, j => Math.pow(-1, j) * this.scale) .map(y => [x, y]) .flatMap(xy => this.flat ? [xy] : _ .times(2, k => Math.pow(-1, k) * this.scale) .map(z => [...xy, z]), ) ) , ..._ .times(2, j => Math.pow(-1, j) * φ * this.scale) .map(y => [0, y]) .flatMap(xy => this.flat ? [xy] : _ .times(2, k => Math.pow(-1, k) * (φ - 1) * this.scale) .map(z => [...xy, z]), ) , ..._ .times(2, i => Math.pow(-1, i) * (φ - 1) * this.scale) .map(x => [x, 0]) .flatMap(xy => this.flat ? [xy] : _ .times(2, k => Math.pow(-1, k) * φ * this.scale) .map(z => [...xy, z]), ) , ..._ .times(2, i => Math.pow(-1, i) * φ * this.scale) .flatMap(x => _ .times(2, j => Math.pow(-1, j) * (φ - 1) * this.scale) .map(y => [x, y]) .map(xy => this.flat ? xy : [...xy, 0] ) ) , ].map(([x, y, ...rest]) => this.mirror ? [y, x, ...rest] : [x, y, ...rest] ); } }
katex` <katex>\tan{\gamma \over 2} = \phi</katex> <katex>\tan \alpha = {\phi \over \phi^{-1}} = \phi^2</katex> <katex> \alpha + \beta + {\gamma \over 2} + 2 \cdot {\pi \over 2} = 2 \pi \rArr </katex> <katex> \alpha + \beta + {\gamma \over 2} = \pi \rArr </katex> <katex> \beta = \pi - (\alpha + {\gamma \over 2}) \rArr </katex> <katex> \tan \beta = \tan(\pi - (\alpha + {\gamma \over 2})) = -\tan(\alpha + {\gamma \over 2}) = -{\tan \alpha + \tan{\gamma \over 2} \over 1 - \tan \alpha \cdot \tan{\gamma \over 2}} = {\tan \alpha + \tan{\gamma \over 2} \over \tan \alpha \cdot \tan{\gamma \over 2} - 1} = {\phi^2 + \phi \over \phi^2 \cdot \phi - 1} = {\phi^3 \over \phi^3 - 1} = {\phi^3 \over (2 \phi + 1) - 1} = {\phi^3 \over 2 \phi} = {\phi^2 \over 2} </katex> <katex> \tan \gamma = \tan({\gamma \over 2} + {\gamma \over 2}) = {2 \tan{\gamma \over 2} \over 1 - \tan^2{\gamma \over 2}} = {2 \phi \over 1 - \phi^2} = {2 \phi \over -\phi} = -2 </katex> <katex> \sin \alpha = \sqrt{\tan^2 \alpha \over 1 + \tan^2 \alpha} = \sqrt{\phi^4 \over 1 + \phi^4} = \sqrt{3 \phi + 2 \over 3 \phi + 3} = \sqrt{(6 - 9)\phi + (9 - 6 - 6) \over 9 - 9 - 9} = \sqrt{3 \phi + 3 \over 9} = {\sqrt{3 \phi^2} \over 3} = {\sqrt{3} \over 3} \phi </katex> <katex> \cos \alpha = \sqrt{1 \over 1 + \tan^2 \alpha} = \sqrt{1 \over 1 + \phi^4} = \sqrt{1 \over 3 \phi + 3} = \sqrt{(3 - 0)\phi + (0 - 3 - 3) \over 9 - 9 - 9} = \sqrt{6 - 3 \phi \over 9} = {\sqrt{3(2 - \phi)} \over 3} = {\sqrt{3 \over \phi^2} \over 3} = {\sqrt{3} \over 3 \phi} = {\sqrt{3} \over 3} (\phi - 1) </katex> <katex> \sin \beta = \sqrt{\tan^2 \beta \over 1 + \tan^2 \beta} = \sqrt{\phi^4 \over 4 + \phi^4} = \sqrt{3 \phi + 2 \over 3 \phi + 6} = \sqrt{(6 - 18)\phi + (9 - 6 - 12) \over 9 - 18 - 36} = \sqrt{12 \phi + 9 \over 45} = \sqrt{4 \phi + 3 \over 15} </katex> <katex> \cos \beta = \sqrt{1 \over 1 + \tan^2 \beta} = \sqrt{4 \over 4 + \phi^4} = \sqrt{4 \over 3 \phi + 6} = \sqrt{(12 - 0)\phi + (0 - 12 - 24) \over 9 - 18 - 36} = \sqrt{36 - 12 \phi \over 45} = 2 \sqrt{3 - \phi \over 15} </katex> <katex> \sin{\gamma \over 2} = \sqrt{\tan^2{\gamma \over 2} \over 1 + \tan^2{\gamma \over 2}} = \sqrt{\phi^2 \over 1 + \phi^2} = \sqrt{\phi + 1 \over \phi + 2} = \sqrt{(1 - 2)\phi + (1 - 1 - 2) \over 1 - 2 - 4} = \sqrt{\phi + 2 \over 5} </katex> <katex> \cos{\gamma \over 2} = \sqrt{1 \over 1 + \tan^2{\gamma \over 2}} = \sqrt{1 \over 1 + \phi^2} = \sqrt{1 \over \phi + 2} = \sqrt{(1 - 0)\phi + (0 - 1 - 2) \over 1 - 2 - 4} = \sqrt{3 - \phi \over 5} </katex> <katex> \sin \gamma = 2 \sin{\gamma \over 2} \cos{\gamma \over 2} = 2 \cdot \sqrt{\phi + 2 \over 5} \cdot \sqrt{3 - \phi \over 5} = {2 \over 5} \sqrt{(\phi + 2)(3 - \phi)} = {2 \over 5} \sqrt{3 \phi - \phi^2 + 6 - 2 \phi} = {2 \over 5} \sqrt{3 \phi - \phi - 1 + 6 - 2 \phi} = {2 \sqrt{5} \over 5} = {2 \cdot (2 \phi - 1) \over 5} = {4 \phi - 2 \over 5} </katex> <katex> \cos \gamma = \cos^2{\gamma \over 2} - \sin^2{\gamma \over 2} = ({3 - \phi \over 5}) - ({\phi + 2 \over 5}) = {3 - \phi - \phi - 2 \over 5} = {1 - 2 \phi \over 5} = -{\sqrt{5} \over 5} </katex> <katex>\alpha = \arctan \phi^2</katex> <katex>\beta = \arctan {\phi^2 \over 2}</katex> <katex>\gamma = 2 \arctan \phi</katex> `;
Object.assign(RegularDodecahedron, (() => { const tan = { alpha: φ + 1, beta: 0.5 * φ + 0.5, gamma: -2, half: { gamma: φ, }, }; const alpha = Math.atan(tan.alpha); const beta = Math.atan(tan.beta); const half = { gamma: Math.atan(tan.half.gamma), }; const gamma = 2 * half.gamma; const sin = { alpha: φ / Math.sqrt(3), beta: Math.sqrt((4 * φ + 3) / 15), gamma: (4 * φ - 2) / 5, half: { gamma: Math.sqrt((φ + 2) / 5), }, }; const cos = { alpha: (φ - 1) / Math.sqrt(3), beta: 2 * Math.sqrt((3 - φ) / 15), gamma: (1 - 2 * φ) / 5, half: { gamma: Math.sqrt((3 - φ) / 5), }, }; return { alpha, beta, gamma, half, cos, sin, tan, }; })());
const regularDodecahedron = new RegularDodecahedron();
function testValues(o, fn, p = []) { return _.mapValues(o, (v, k) => _.isPlainObject(v) ? testValues(v, fn, [...p, k]) : Math.log(Math.abs(v - fn(_.get(RegularDodecahedron, [...p, k])))) / Math.LN2 ); }
testValues(RegularDodecahedron.sin, Math.sin);
testValues(RegularDodecahedron.cos, Math.cos);
testValues(RegularDodecahedron.tan, Math.tan);
module.exports = { RegularDodecahedron, regularDodecahedron, };
Loading…

no comments

    sign in to comment