MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Two programming challenges

  • To: mathgroup at
  • Subject: [mg14411] Re: [mg14374] Two programming challenges
  • From: Jurgen Tischer <jtischer at>
  • Date: Sun, 18 Oct 1998 15:10:14 -0400
  • Organization: Universidad del Valle
  • References: <>
  • Sender: owner-wri-mathgroup at

Ok Will,
here is my candidate for challenge 1. The idea is to peel the set like
an onion with ConvexHull, which gives the outer points already in order
and then join the onion skins. I return the last point of every skin to
the residual set, to use it as the start of the next one.

<< "DiscreteMath`ComputationalGeometry`"

spiral[li1_, li2_] := 
  Module[{ch = ConvexHull[li2], pp}, 
   pp = aux[li2[[ch]], li1[[-1]]]; 
    spiral[Join[li1, Drop[pp, 1]], 
     Append[Delete[li2, Transpose[{ch}]], pp[[-1]]]]]

spiral[{}, li_] := 
  With[{ch = ConvexHull[li]}, spiral[li[[ch]], 
    Delete[li, Transpose[{Drop[ch, -1]}]]]]

spiral[li_, {x_}] := li

spiral[li_] := spiral[{}, li]

aux[li_, p_] := RotateLeft[li, Position[li, p][[1]] - 1]

(* the rest is to show that it works *)

randomData[n_] := Table[{Random[], Random[]}, {n}]

showSpiral[li_] := Show[Graphics[Line[spiral[li]]], AspectRatio ->

showSpiral[rd = randomData[60]]


Will Self wrote:
> Mathematica Programming Challenge 1
> Given several points in the plane, connect these points by line
> segments, resulting in a connected polygonal line that passes through
> all the points and does not intersect itself.  Arrange it so that the
> line seems to spiral inwards.
> Mathematica Programming Challenge 2
> There are two rhombi, named after Penrose, which you can use to tile the
> plane.  They both have the same edge length; the narrower rhombus has a
> tip angle of Pi/5, and the wider rhombus has a tip angle of 2Pi/5.
> Write a program that produces random (whatever that means) tesselations
> of (part of) the plane, using these two shapes.
> Will Self

  • Prev by Date: Re: Routines inside Epilog
  • Next by Date: Re: Adding equations
  • Previous by thread: Two programming challenges
  • Next by thread: Re: Two programming challenges