Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Two programming challenges

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14411] Re: [mg14374] Two programming challenges
  • From: Jurgen Tischer <jtischer at col2.telecom.com.co>
  • Date: Sun, 18 Oct 1998 15:10:14 -0400
  • Organization: Universidad del Valle
  • References: <199810150429.AAA18352@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

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 ->
Automatic]

showSpiral[rd = randomData[60]]


Jurgen

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