Drawing uniform polyhedra with Javascript, WebGL and Three.js
Source on Github
Introduction
The
Wythoff
construction is an elegant way of constructing polyhedra from
a basic spherical tiling, represented
by Schwarz
triangles.
Using the construction, combined with some fairly straightforward
vector geometry, we can generate 3D models of uniform polyhedra and
their derivatives: we use a kaleidoscopic construction to generate
the Schwarz triangles and then use trilinear (or maybe triplanar or
even trihedral - distance from 3 coincident planes anyway)
coordinates within each triangle to determine the polyhedron
vertices, with the trilinear coordinates being converted to
barycentric (or maybe trihedral or even triplanar - the weighted sum
of three points anyway, which I suppose makes them a non-orthogonal
basis for ℝ³) for actually generating the points. Vertices for snub
polyhedra are found by iterative approximation. We can also use this
information to generate duals and stellations as well as using the
Schwarz triangle tiling to apply further symmetry operations to
basic polyhedra to create compounds.
Using the excellent Three.js
Javascript library from Mr.doob, we
can do all this with WebGL in real time.
Examples
Sequences
Given a Schwarz triangle, we can move around inside that
triangle to create different polyhedra (ie. given a set of
mirrors, we can move the vertex point around inside those
mirrors). A position within the triangle can be specified
with trilinear coordinates representing the relative distance of
the point from the three sides eg. (1,1,1) is the central point
(perhaps they really should be called triplanar coordinates). We
don't have to stay within the triangle though and in fact the
point can be anywhere in space (or rather, since we scale vertex
points to have length 1, anywhere on the sphere where a sequence
of coordinates such as [-1,1,0], [1,1,0], [1,-1,0], [-1,-1,0]
corresponds to a great circle route).
- [3 5 2]: Convex icosahedral symmetry
- [3
4 2]: Moving around the kaleidoscope often corresponds to
well-know transformations of polyhedra, here we see the
truncation cycle of the cube.
- [5
3 2]: Icosahedral symmetry outside the Schwarz triangle. The resemblance to
Jonathan
Bower's "tribes"
probably isn't coincidence.
- [5/4 5/4 5/4]
- [2 5/3 3/2]
- [3 5/3 2]
- [3 5/3 5/2] U69 looks good in granite
- U72 A particularly fine snub figure
- Jitterbug
transformation Another polyhedral transformations that
corresponds to a particular route through a Schwarz triangle
(snub this time) - here the triangle is [2 x x] and the route is
from 1,0,0 to 0,1,1 (via 1,1,1 - the main snub figure).
- Verheyen's Vampire A "dipolygonid" transformation, with two sets of oppositely oriented icosahedral triangles. That 0.618 in the trilinear coordinates can't be a coincidence.
We can also show dual figures, and also use inversion to display the original polyhedra, but in a different way:
Sometimes we need a little adjustment of the polyhedron before display, for example, to omit a set of faces or add "hemi" faces through the origin (we cheat a little here and just add a triangle connecting each edge with the origin, rather than adding a proper face).
[2 2 1] doesn't make for a very interesting polyhedron, but we can use it as a symmetry to combine mirror images of other polyhedra. We can use two copies of U69, with "hemi faces" added and certain other sets of faces hidden. The result is the two uniform polyhedra that cannot be made by a "minute variation" of the Wythoff construction (this method of constructing these polyhedra from U69 is described by Zvi Har’El):
A few other examples:
Cubic surfaces
Cubic surfaces (zero loci of degree-3 homogeneous polynomials, to be precise) usually have their natural home in complex projective space, but can be projected down to our familiar real euclidean 3-space. Here we display some as collections of particles (this looks nice and is easier than doing a proper triangulation). The projection is controlled by a basic matrix as well as applying a quaternion rotation for animation. See
here for some more details.
Controls here are: z/x: decrease/increase scale, [/]: go slower/faster, c: change color scheme, p: change projection, q: change rotation quaternion, r: reset, s: change surface, t: toggle twirling, <space>: toggle rotation, <up>/<down>: move in & out, ?: toggle info, plus the usual orbit controls with the mouse.
- The Clebsch Surface The most famous cubic surface, also showing the equally famous 27 lines.
- A classic view of the Clebsch Surface, aligned vertically and with a bounding sphere.
- The Cayley Surface Another nice cubic surface with 4 double points and just 9 lines.
- Morphing cubic. Transforming between the Clebsch and Cayley cubics. Controls as above plus m: toggle morphing.
- The Barth Sextic. Not a cubic of course. Icosahedral symmetry.
OFF files
We can load files in OFF format (for example, as generated by the excellent
Antiprism tools) and display with various embellishments. Compounding is also possible (though may be slow if the OFF file contains many vertices):
Some
Antiprism examples:
And a couple from
Roger Kaufman:
Linkages & Dipolygonids
For a polyhedron with all edge lengths equal, we can replace each
edge with a hinged pair of brackets that allows the polyhedron to
be collapsed like an umbrella (the angle of the bracket is chosen
to preserve the angle made at the centre). This is appararently
the
Hoberman
sphere. Makes a
nice
toy.
Some examples of Verheyen's dipolygonid construction - a
generalization of Buckminster Fuller's Jitterbug. See
this
paper
Miscellaneous
Various other geometric experiments, using the same framework.
- Into the 4th dimension: an Omnitruncated Tesseract. A 80-cell uniform polychoron, with a vertex for each of the 384 elements of the hyperoctahedral group. '9' and '0' zooms in and out (hither and yon?) in 4-space; <space> toggles rotation in 4-space. See code for the Wythoff construction in 4 dimensions.
- The 120-cell: the underlying symmetry group has 14400 elements.
- A duoprism
- Infinite Descent An experiment in zooming in. Zooming out reveals the truth.
- A zonohedron:
a vast and fascinating area of polyhedral
studies. Here we see the zonohedrification of the
zonohedifrication of an icosidodecahedron (using the vertex
vectors for the zonohedrification). The algorithm is
from George
Hart. Faces are coloured according to surface area (I think an idea due
to Russell
Towle originally).
-
A star zonohedron A 3-vector star, triple-zonohedrified.
-
Tetrahedral compound of 50-star polar zonohedron Perhaps something one might find in the Pitt Rivers.
- Semiregular
polygons A test for drawing retroflex edges, but quite
fun in its own right. Not sure if
there is a standard meaning of "semiregular" for polygons - here we mean
alternate edges and angles are the same, with vertices at
2imπ/n ± θ, for 0 ≤ i < n, with θ varying.
- 17/7
polygon - construct that!
- Another
Jitterbug rendition This one constructed from the basic geometry.
- A nice
theorem: joins of opposite edge bisectors in a tetrahedron
are coincident. The yellow vertices clearly form a parallelogram.
The tetrahedron is constructed in 4-space, rotated with a quaternion & projected into
3-space in the usual way.
- Desargues Theorem Constructed from two congruent tetrahedra, then rotated in projective space.
- Desargues Theorem again A slice through a pentatope forms a Desargues configuration. The green vertices are the points of intersection with the hyperplane normal to [4,3,2,1]
- Desmic tetrahedra A "desmic" configuration of 3 tetrahedra, each edge of which intersects an edge of the other two, and with each pair in perspective from each vertex of the third
- SLERP A square rotated 360 degrees in 32 steps with a SLERPed quaternion, with the quaternion itself changing over time. Note that one square and one vertex of each color never move.
- Rotations
- Origami Simple rigid folding
Uniform Compounds
Instead of using a set of Schwarz triangles to draw a polyhedron,
we can use the triangle sides as a set of mirrors to apply a set
of symmetries to another polyhedron - our Schwarz triangle
construction gives an axis of symmetry along the z-axis so
rotating around that axis gives different alignments. This seems
to include the full set of Uniform Compounds enumerated by
Skilling, as well as many other combinations where eg. vertex
transitivity fails. See George Hart's pages on
Compound
Polyhedra for more details.
References
Mouse Controls
Uses Three.js OrbitControls: use mouse click and drag to rotate figure. Mouse wheel to zoom.
Keyboard Controls
- Up arrow: move forward
- Down arrow: move backward
- space: animation on/off
- r: rotation on/off
- p: return animation to start
- [: step animation back 1
- ]: step animation forward 1
- u: rotate colors
- f: step through color styles
- i: inversion on/off
- s: snub on/off
- d: change dual mode
- y: change dual style
- q: stellate on/off
- h: hemi on/off
- n: normalize on/off
- c: compound on/off
- z: z rotation for compounds on/off
- a: reset z rotation
- t: change the tour around the Schwarz triangle
- T: textures on/off
- x: rotation only for compounds on/off
- e: explode faces
- w: implode faces
- =: increase triangulation depth
- -: decrease triangulation depth
- 1-4: hide/reveal face
Changes
- 7/1/15: Bugfix: no display on OFF file load
- 7/1/15: Feature: U73 example normalmap
- 7/1/15: Feature: added normalmaps, "&normal=XXX.jpg"
- 8/1/15: Feature: added Jitterbug example
- 17/1/15: Added edge linkage examples
- 17/1/15: Added dipolygonid examples
- 17/1/15: Default symmetry now 2:2:1 ie. one mirror image
- 17/1/15: Bugfix: don't try and handle control characters
- 17/1/15: Bugfix: Trilinear coordinates had second & third
values swapped
- 24/1/15: Added polygon example
- 24/1/15: Added cube truncation example
- 24/1/15: Better tours
- 24/1/15: Zonohedra beta
- 27/1/15: Bugfix: draw retroflex edges properly
- 30/1/15: Tidied up interfaces to off functions
- 31/1/15: Added zonohedron example
- 16/2/15: Added 80-cell.
- 21/2/15: Update to Three.js r74.
- 21/2/15: BufferGeometry for polyhedra.
- 21/2/15: Added dynamic 80-cell example.
- 21/2/15: Added zoomer.
- 23/2/15: BufferGeometry for OFF geometries
- 27/2/15: Added Clebsch surface
- 27/2/15: Remove keypress handling from non-full-window views
- 11/3/15: Added SLERP demo
- 13/3/15: Configurable polychora & demos
- 16/3/15: Rotations demo
- 22/3/15: Desargues2 demo
- 10/4/15: More cubic surfaces
- 21/4/15: Adding a twirl