Re: testing if a point is inside a polygon

• To: mathgroup at smc.vnet.net
• Subject: [mg96496] Re: testing if a point is inside a polygon
• From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
• Date: Sat, 14 Feb 2009 03:14:35 -0500 (EST)
• References: <gmp0mt\$btn\$1@smc.vnet.net> <200902121138.GAA08476@smc.vnet.net>

You're right. It's a left-over that I forgot and Daniel's code could
have been reduced even more.

On Feb 13, 10:40 am, Andrzej Kozlowski <a... at mimuw.edu.pl> wrote:
> I know it's only a matter of "taste" but to me using Module without
> any local variables is like eating rice with knife and fork. Can be
> done but why?
>
> Andrzej Kozlowski
>
> On 12 Feb 2009, at 11:38, Sjoerd C. de Vries wrote:
>
> > Since timing is often important for functions like this one, I've
> > compared the various algorithms posted here using David's two tests.
> > The results are below:
>
> > {
> > {"Daniel", 0.828, 1.219},
> > {"Daniel/Sjoerd", 0.688, 1.078},
> > {"Sedgewick/Sjoerd", 0.688, 0.954},
> > {"David1", 41.766, 81.89},
> > {"David2", 1.578, 2.531},
> > {"Godkin/Frank", 1.485, 2.359}
> > }
>
> > In the "Daniel/Sjoerd" method I have used Daniel's code and taken out
> > every intermediate step. This saves an additional 20%. The code is now
> > completely gibberish, but it still works ;-)
>
> > PointInsidePolygonQ[pt_, poly_] :=
> > Module[{},
> >  Equal @@
> >     Dot, {pt - # & /@
> >       poly, {{0, 1}, {-1, 0}}.# & /@ (Subtract @@ # & /@
> >         Partition[Append[poly, poly[[1]]], 2, 1])}]
> >  ]
>
> > Cheers --Sjoerd
>
> > On Feb 9, 12:31 pm, Mitch Murphy <mi... at lemma.ca> wrote:
> >> is there a way to test whether a point is inside a polygon? ie.
>
> >>        PointInsidePolygonQ[point_,polygon_] -> True or False
>
> >> i'm trying to do something like ...
>
> >>        ListContourPlot[table,RegionFunction->CountryData["Cana=
da=
> > ","Polygon"]]
>
> >> to create what would be called a "clipping mask" in photoshop.
>
> >> cheers,
> >> Mitch

• Prev by Date: Re: New free introductory book on Mathematica programming,
• Next by Date: Re: Problem with DSolve
• Previous by thread: Re: Re: testing if a point is inside a polygon
• Next by thread: Re: testing if a point is inside a polygon