$SPAD/src/input antoine.input

The Axiom Team December 3, 2016

Abstract

Contents

2

1 License

— license —

--Copyright The Numerical Algorithms Group Limited 1994.

———-

Draw Antoine’s Necklace. Thanks to Matt Grayson (formerly at IBM’s T.J Watson Research Center) for the idea.

Bring DH matrices into the environment — * —

)set break resume
)spool antoine.output
)set message test on
)set message auto off
)clear all
--S 1 of 11
)set expose add con DenavitHartenbergMatrix
--R
--I   DenavitHartenbergMatrix is now explicitly exposed in frame frame0
--E 1

———-

Create Affine transformations (DH matrices) that transform a given triangle into another given triangle

tri2tri(t1, t2) returns a DHMATRIX which transforms t1 to t2, where t1 and t2 are the vertices of two triangles in 3-space.

— * —

--S 2 of 11
tri2tri(t1: List Point DoubleFloat, t2: List Point DoubleFloat): _
 DHMATRIX(DoubleFloat) ==
  n1 := triangleNormal(t1)
  n2 := triangleNormal(t2)
  tet2tet(concat(t1, n1), concat(t2, n2))
--R
--R   Function declaration tri2tri : (List(Point(DoubleFloat)),List(Point(
--R      DoubleFloat))) -> DenavitHartenbergMatrix(DoubleFloat) has been
--R      added to workspace.
--R                                                                   Type: Void
--E 2

———-

tet2tet(t1, t2) returns a DHMATRIX which transforms t1 to t2, where t1 and t2 are the vertices of two tetrahedrons in 3-space.

— * —

--S 3 of 11
tet2tet(t1: List Point DoubleFloat, t2: List Point DoubleFloat): _

 DHMATRIX(DoubleFloat) ==
  m1 := makeColumnMatrix t1
  m2 := makeColumnMatrix t2
  m2 * inverse(m1)
--R
--R   Function declaration tet2tet : (List(Point(DoubleFloat)),List(Point(
--R      DoubleFloat))) -> DenavitHartenbergMatrix(DoubleFloat) has been
--R      added to workspace.
--R                                                                   Type: Void
--E 3

———-

put the vertices of a tetrahedron into matrix form — * —

--S 4 of 11
makeColumnMatrix(t) ==
  m := new(4,4,0)$DHMATRIX(DoubleFloat)
  for x in t for i in 1..repeat
    for j in 1..3 repeat
      m(j,i) := x.j
    m(4,i) := 1
  m
--R
--R                                                                   Type: Void
--E 4

———-

return a vector normal to the given triangle, whose length is the square root of the area of the triangle

— * —

--S 5 of 11
triangleNormal(t) ==
  a := triangleArea t
  p1 := t.2 - t.1
  p2 := t.3 - t.2
  c := cross(p1, p2)
  len := length(c)
  len = 0 => error "degenerate triangle!"
  c := (1/len)*c
  t.1 + sqrt(a) * c
--R
--R                                                                   Type: Void
--E 5

———-

compute the are of a triangle using Heron’s formula — * —

--S 6 of 11

triangleArea t ==
a := length(t.2 - t.1)
b := length(t.3 - t.2)
c := length(t.1 - t.3)
s := (a+b+c)/2
sqrt(s*(s-a)*(s-b)*(s-c))
--R
--R                                                                   Type: Void
--E 6

———-

The current transformation for drawing a sub-ring — * —

--S 7 of 11
torusRot: DHMATRIX(DoubleFloat)
--R
--R                                                                   Type: Void
--E 7

———-

Draw Antoine’s Rings with n levels of recursive subdivision. The number of subrings is 10^{n}. — * —

--S 8 of 11
drawRings(n) ==
s := create3Space()$ThreeSpace DoubleFloat
-- create an identity transformation
dh:DHMATRIX(DoubleFloat) := identity()
drawRingsInner(s, n, dh)
makeViewport3D(s, "Antoine's Necklace")
--R
--R                                                                   Type: Void
--E 8

———-

Recursively draw Antoine’s Necklace.

— * —

--S 9 of 11
drawRingsInner(s, n, dh) ==
n = 0 =>
  drawRing(s, dh)
  void()
t := 0.0@DoubleFloat             -- the current angle around the ring
p := 0.0@DoubleFloat             -- the angle of the subring from the plane
tr := 1.0@DoubleFloat            -- the amount to translate the subring
inc := 0.1@DoubleFloat           -- translation increment
-- subdivide the ring into 10 linked rings
for i in 1..10 repeat
  tr := tr + inc

    inc := -inc
    dh' := dh * rotatez(t) * translate(tr, 0.0@DoubleFloat, 0.0@DoubleFloat) *
           rotatey(p) * scale(0.35@DoubleFloat, 0.48@DoubleFloat, 0.4@DoubleFloat)
    drawRingsInner(s, n-1, dh')
    t := t + 36.0@DoubleFloat
    p := p + 90.0@DoubleFloat
  void()
--R
--R                                                                   Type: Void
--E 9

———-

draw a single ring into the given subspace, transformed by the given DHMATRIX. — * —

--S 10 of 11
drawRing(s, dh) ==
  free torusRot
  torusRot := dh
  makeObject(torus, 0..2*%pi, 0..2*%pi, var1Steps == 6, space == s,
             var2Steps == 15)
--R
--R                                                                   Type: Void
--E 10

———-

Parameterization of a torus, transformed by the DHMATRIX in torusRot. — * —

--S 11 of 11
torus(u ,v) ==
  cu := cos(u)/6
  torusRot * point [(1+cu)*cos(v), (1+cu)*sin(v), (sin u)/6]
--R
--R                                                                   Type: Void
--E 11
)spool
)lisp (bye)

———-

References^{[1] nothing}

7