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]
);
}
}