Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Polygon cutter

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87948] Re: Polygon cutter
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Mon, 21 Apr 2008 03:24:20 -0400 (EDT)
  • References: <fueen3$b74$1@smc.vnet.net>

Hi,

what is wrong with ContourPlot[] to reinvent the weel?
Except the good old numeric code, nobody would use code
from 1966 that has not updated over the time.

And what is wrong with the good old Which[] function
of Mathematica ?

Regards
   Jens

carlos at colorado.edu wrote:
> A programming style question.  The code fragments below come
> from conversion to Mathematica (they must work on versions
>  >=4.0) of an ancient Fortran IV contourplot program written
> in 1966 for my thesis. They are key part of the inner loop
> "polygon cutter".
> -----------------------------------------------------------
> Version 1. Straight translation from Fortran:
> 
> p={Null};
> If [tb>0&&tb==tt,  p={P1,P2,P4,P3}];
> If [tb==1&&tt==2,  p={Pc2,P1,P2,P4,P3}];
> If [tb==-1&&tt==-1,p={}];
> If [tb==-1&&tt==0, p={Pc1,Pc2,Pc3}];
> If [tb==-1&&tt==1, p={Pc1,P4,P3}];
> If [tb==-1&&tt==2, p={Pc1,Pc2,P3,P4}];
> If [tb==0&&tt==0,  p={}];
> If [tb==1&&tt==0,  p={Pc3,Pc2,P1,P2}];
> If [tb==2&&tt==0,  p={Pc3,P1,P2}];
> poly=Graphics[Polygon[p]];
> 
> V1 was actually a separate subroutine, with a RETURN after
> each match, but in Mathematica it goes inline.
> tb (tag-bottom) and tt (tag-top) are integers in range
>  -1 through 2 whereas P1, ... etc, are point coordinates.
> -----------------------------------------------------------
> Version 2. Table driven variant of above:
> 
> p={{{},{Pc1,Pc2,Pc3},{Pc1,P4,P3},{Pc1,Pc2,P3,P4}},
>    {{Null},{},{Null},{Null}},
>    {{Null},{Pc3,Pc2,P1,P2},{P1,P2,P4,P3},{Pc2,P1,P2,P4,P3}},
>    {{Null},{Pc3,P1,P2},{Null},{P1,P2,P4,P3}}} [[tb+2,tt+2]];
> poly=Graphics[Polygon[p]];
> 
> Impossible (tb,tt) combinations return {Null}. V2 was
> actually that implemented when V1 was later converted to
> Univac 1110 machine language.
> ----------------------------------------------------------
> Question: which version is preferable in Mathematica, or is
> there a better one? Both run roughly at the same speed
> (about 25 microsec under 5.2 on an Intel MacBook Pro).
> Since this  loop is traversed once for each polygon,
> efficiency is important.
> 


  • Prev by Date: Re: Print[Plot] vs Print[text,Plot]?
  • Next by Date: Re: How to remove unneeded constraints
  • Previous by thread: Re: Polygon cutter
  • Next by thread: Re: Polygon cutter