MathGroup Archive 2009

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

Search the Archive

Re: Re: testing if a point is inside a polygon

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96408] Re: [mg96369] Re: testing if a point is inside a polygon
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 13 Feb 2009 03:41:12 -0500 (EST)
  • References: <gmp0mt$btn$1@smc.vnet.net> <200902121138.GAA08476@smc.vnet.net>

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 @@
>   Sign@MapThread[
>     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["Canada=
> ","Polygon"]]
>>
>> to create what would be called a "clipping mask" in photoshop.
>>
>> cheers,
>> Mitch
>
>



  • Prev by Date: Re: Definition of the similarity in a set of integers
  • Next by Date: Re: Best syntax for derivative
  • Previous by thread: Re: testing if a point is inside a polygon
  • Next by thread: Re: testing if a point is inside a polygon