MathGroup Archive 2008

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

Search the Archive

Polygon cutter

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:

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}];

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:

   {{Null},{Pc3,P1,P2},{Null},{P1,P2,P4,P3}}} [[tb+2,tt+2]];

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: Problems to find the local extrema of an InterpolatingFunction
  • Next by Date: Re: A kernel, multiple notebooks, and Global?
  • Previous by thread: Re: How to remove unneeded constraints
  • Next by thread: Re: Polygon cutter