Skip to content

Generate polyhedra using Conway polyhedron notation

Notifications You must be signed in to change notification settings

mlechu/shape-rotator

Repository files navigation

shape rotator

Generate polyhedra using Conway polyhedron notation. Implemented in Prolog.

Dependencies

The program requires SWI Prolog, which available here (or with nix, do nix develop).

Usage

swipl main.pl

gen_shape("your string here").

Some examples:

  • gen_shape("eD").
  • gen_shape("dkC").
  • gen_shape("aI").

Your string should end with one of the supported seed shapes (see below), and can have operators to the left of the seed which are applied from right to left.

Uppercase seed shapes:

  • T (tetrahedron)
  • C (cube)
  • O (octahedron)
  • D (dodecahedron)
  • I (icosahedron)

Operations:

  • a (ambo)
  • d (dual)
  • g (gyro) [not yet implemented]
  • k (kis)
  • j (join)
  • s (snub) [not yet implemented]
  • t (truncate)
  • b (bevel)
  • e (expand)
  • m (meta)
  • o (ortho)
  • n (needle)
  • z (zip)

Viewing STL output

Find output files in ./out. If you have macOS, you can rotate the generated 3D shapes in Preview.app! Viewers are available online, too.

Internals

  • Until it’s time to render them, polyhedra are represented as follows:
    ap([face([edge(point(1,2,3), point(4,5,6))
              edge(point(1,2,3), point(9,8,7))
              edge(point(4,5,6), point(9,8,7)) ...])
        face([...])
        face([...])
        face([...]) ...])
        

    The order of face~s within the ~ap does not matter, nor does the order of the edges within the face.

    The order of point~s within the ~edge(A, B) does matter (A @=< B) for easier edge comparison.

  • For STL output, each face is broken into triangles.
  • Several assumptions are made about the properties of the polyhedron. If you manage to violate them (which is not difficult at the moment), you’ll probably get some fun visual bugs (or a div/0 error.)
    • Every face(edge1, edge2, edge3, ...) lies flat in some plane. This is probably the easiest to break.
    • Every 2d and 3d shape is always convex (and consequently, the midpoint of any face is inside the face)
    • No edge or face would intersect the origin when extended. I think we even assume that the origin always lies inside the 3d shape.
  • Generally a variable X0 is the untransformed version of X

Features to add

  • gyro operator and friends
  • Improve kis, which naively puts a constant-height pyramid on each face
  • reflect (easy)
  • number of vertices, edges, faces
  • symmetry stats, groups
  • SVG output (project to 2d)
  • Comparison with known polyhedra (graph isomorphism)
  • Better normalization

Resources

About

Generate polyhedra using Conway polyhedron notation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published