Polyhedra

Polyhedra

More fun with Fluxus - I've been learning how to use (build-polygons), where you define the vertices that make up the faces (and the normals to the faces which control lighting). I had a heck of a time getting the tetrahedron working, I found that (recalc-normals) didn't work in a way that was suitable. The function (hint-normal) shows the normals as red lines, so you can check they are pointing in the right directions, very helpful. Once I got used to it, making an octahedron was much easier.

(define (pow a b) (exp (* (log a) b)))

(define (build-octahedron)
  (let ((ob (build-polygons 24 2))
        (L (pow (/ 1 3) (/ 1 3)) )
        (-L (- 0 (pow (/ 1 3) (/ 1 3))))
       )

    (grab ob)

    (pdata-set "p"  0 (vector  1  0  0))
    (pdata-set "p"  1 (vector  0  1  0))
    (pdata-set "p"  2 (vector  0  0  1))

    (pdata-set "p"  3 (vector  1  0  0))
    (pdata-set "p"  4 (vector  0  0  1))
    (pdata-set "p"  5 (vector  0 -1  0))

    (pdata-set "p"  6 (vector  1  0  0))
    (pdata-set "p"  7 (vector  0 -1  0))
    (pdata-set "p"  8 (vector  0  0 -1))

    (pdata-set "p"  9 (vector  1  0  0))
    (pdata-set "p" 10 (vector  0  0 -1))
    (pdata-set "p" 11 (vector  0  1  0))

    (pdata-set "p" 12 (vector -1  0  0))
    (pdata-set "p" 13 (vector  0  0  1))
    (pdata-set "p" 14 (vector  0  1  0))

    (pdata-set "p" 15 (vector -1  0  0))
    (pdata-set "p" 16 (vector  0 -1  0))
    (pdata-set "p" 17 (vector  0  0  1))

    (pdata-set "p" 18 (vector -1  0  0))
    (pdata-set "p" 19 (vector  0  0 -1))
    (pdata-set "p" 20 (vector  0 -1  0))

    (pdata-set "p" 21 (vector -1  0  0))
    (pdata-set "p" 22 (vector  0  1  0))
    (pdata-set "p" 23 (vector  0  0 -1))


    (pdata-set "n"  0 (vector  L  L  L))
    (pdata-set "n"  1 (vector  L  L  L))
    (pdata-set "n"  2 (vector  L  L  L))

    (pdata-set "n"  3 (vector  L -L  L))
    (pdata-set "n"  4 (vector  L -L  L))
    (pdata-set "n"  5 (vector  L -L  L))

    (pdata-set "n"  6 (vector  L -L -L))
    (pdata-set "n"  7 (vector  L -L -L))
    (pdata-set "n"  8 (vector  L -L -L))

    (pdata-set "n"  9 (vector  L  L -L))
    (pdata-set "n" 10 (vector  L  L -L))
    (pdata-set "n" 11 (vector  L  L -L))

    (pdata-set "n" 12 (vector -L  L  L))
    (pdata-set "n" 13 (vector -L  L  L))
    (pdata-set "n" 14 (vector -L  L  L))

    (pdata-set "n" 15 (vector -L -L  L))
    (pdata-set "n" 16 (vector -L -L  L))
    (pdata-set "n" 17 (vector -L -L  L))

    (pdata-set "n" 18 (vector -L -L -L))
    (pdata-set "n" 19 (vector -L -L -L))
    (pdata-set "n" 20 (vector -L -L -L))

    (pdata-set "n" 21 (vector -L  L -L))
    (pdata-set "n" 22 (vector -L  L -L))
    (pdata-set "n" 23 (vector -L  L -L))

    (finalise)

    (ungrab)

    ob

  )
)