home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / sci / math / symbolic / 2417 < prev    next >
Encoding:
Text File  |  1992-09-14  |  2.4 KB  |  81 lines

  1. Newsgroups: sci.math.symbolic
  2. Path: sparky!uunet!spool.mu.edu!yale.edu!ira.uka.de!chx400!bernina!neptune!maeder
  3. From: maeder@inf.ethz.ch (Roman Maeder)
  4. Subject: Re: Mma Koch Snowflake in Not. of AMS
  5. Message-ID: <1992Sep15.074447.9065@neptune.inf.ethz.ch>
  6. Sender: news@neptune.inf.ethz.ch (Mr News)
  7. Nntp-Posting-Host: arcturus.inf.ethz.ch
  8. Reply-To: maeder@inf.ethz.ch (Roman Maeder)
  9. Organization: Theoretical Computer Science, ETH Zurich
  10. References: <1992Sep13.205317.28950@cco.caltech.edu>
  11. Date: Tue, 15 Sep 1992 07:44:47 GMT
  12. Lines: 67
  13.  
  14.       It appears that I either copied this program incorrectly,
  15.       there was a typo in the publication (please see comment below),
  16.       or the program is not correct.
  17.  
  18.       According to the 1991 version (2nd edition) of Wolfram's
  19.       Mathematica book, FixedPoint does not allow multiple arguments.
  20.  
  21. there is a comma at the end of the argument list of FixedPoint,
  22. giving it an addition Null argument.
  23.  
  24. KochSnowflake[n_Integer?NonNegative]:=
  25.   Show[Graphics[FixedPoint[
  26.   (#1/.Line[{start_,finish_}]
  27.   :>doline[start,finish]) &,
  28.   {Line[{{0,0},{1/2,Sqrt[3]/2}}],
  29.   Line[{{1/2,Sqrt[3]/2},{1,0}}],
  30.   Line[{{1,0},{0,0}}]},
  31.   n,]],
  32.   AspectRatio->Automatic,PlotRange->All]
  33.  
  34. it should read
  35.  
  36. KochSnowflake[n_Integer?NonNegative]:=
  37.   Show[Graphics[FixedPoint[
  38.   (#1/.Line[{start_,finish_}]
  39.   :>doline[start,finish]) &,
  40.   {Line[{{0,0},{1/2,Sqrt[3]/2}}],
  41.   Line[{{1/2,Sqrt[3]/2},{1,0}}],
  42.   Line[{{1,0},{0,0}}]},
  43.   n]],
  44.   AspectRatio->Automatic,PlotRange->All]
  45.  
  46. A minor stylistic point: Since you are not really computing the fixed-point,
  47. but stopping after n iteration, I would suggest to use Nest[] instead
  48. of FixedPoint[] (same calling sequence)
  49.  
  50. Here's the whole program again:
  51.  
  52. (*  program for a Koch snowflake.  found in the Notices
  53.     of the AMS Vol.39 #7 Sept 92, page 709    *)
  54.  
  55. KochSnowflake[n_Integer?NonNegative]:=
  56.   Show[Graphics[
  57.     Nest[ (#1/.Line[{start_,finish_}] :>doline[start,finish]) &,
  58.           {Line[{{0,0},{1/2,Sqrt[3]/2}}],
  59.            Line[{{1/2,Sqrt[3]/2},{1,0}}],
  60.            Line[{{1,0},{0,0}}]},
  61.           n]],
  62.    AspectRatio->Automatic,PlotRange->All]
  63.  
  64. doline[start_,finish_]:=
  65.   Module[{vec,normal},
  66.   vec=finish-start;
  67.   normal=Reverse[vec] {-1,1} Sqrt[3]/6;
  68.   {Line[{start,start + vec/3}],
  69.   Line[{start + vec/3,start + vec/2 + normal}],
  70.   Line[{start + vec/2 + normal, start + 2 vec/3}],
  71.   Line[{start + 2 vec/3, finish}]
  72.   }
  73.   ]
  74.  
  75.  
  76. Roman Maeder
  77. Theoretical Computer Science
  78. ETH Zentrum, IFW
  79. 8092 Zurich
  80. Switzerland
  81.