MathGroup Archive 2008

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

Search the Archive

Re: Polygon cutter

  • To: mathgroup at
  • Subject: [mg87934] Re: [mg87901] Polygon cutter
  • From: "W_Craig Carter" <ccarter at>
  • Date: Mon, 21 Apr 2008 03:21:44 -0400 (EDT)
  • References: <>

Hello Carlos,
I believe the interpretation of good style is a bit like ethics--it's
easy to agree in extreme cases, but the in-between cases are

I think this depends on whether you intend to modify the code in the
future. I believe V1 is easier to read, and if you think that someone
else may wish to modify it, then I recommend sticking with that.
However,"Which" will probably be more efficient, and rank the order of
tests with decreasing frequency.

V2 looks cool--some people like that.  There is probably  a way to
improve the coolness even more, and remove the need to return the
impossible "Null"s.  Creating V2 probably hones your skills and is
more interesting to do, which is similarly important; but probably has
a direct impact on a broader interpretation of efficiency.

On Sat, Apr 19, 2008 at 11:49 PM,  <carlos at> wrote:
> A programming style question.  The code fragments below come

>  Version 1. Straight translation from Fortran:
>  p={Null};
>  If [tb>0&&tb==tt,  p={P1,P2,P4,P3}];
>  poly=Graphics[Polygon[p]];

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

>  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.

W. Craig Carter

  • Prev by Date: Re: Print[Plot] vs Print[text,Plot]?
  • Next by Date: Re: Print[Plot] vs Print[text,Plot]?
  • Previous by thread: Polygon cutter
  • Next by thread: Re: Polygon cutter