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

MathGroup Archive 2001

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

Search the Archive

Re: Interior of a polygon

  • To: mathgroup at
  • Subject: [mg28682] Re: [mg28543] Interior of a polygon
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Tue, 8 May 2001 02:51:17 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

I have found a little time to implement the solution to Mariusz Jankowski's
problem which I sketched in an earlier posting in reply to his original
message. It only works for convex polygons but can be easily extended to all
by means of Martin Kraus' Polygonal trianulation package. The main be bugs
because I have tested only for a single polygon (given below). The only
improvement on the original idea which I described is to use the
GenericCylindricalAlgebraicDecomposition instead of
CylindricalAlgebraicDecomposition, which ought to make the function much

Here is my function:

<<<< Experimental`

PointsInsidePolygon[poly_List] :=
      rule1 = {Less[a_, x_, b_] :> {x, Ceiling[a], Floor[b]},
          Inequality[a_, Less, x_, Less, b_] :> {x, Ceiling[a], Floor[b]}},
      rule2 = {{u_, w_} :> Table[{x, y}, u, w]}},
    ineq[{{a_, b_}, {a_, d_}, {e_, f_}}] := If[e > a, x > a, x < a];
ineq[{{a_, b_}, {c_, d_}, {e_, f_}}] :=
      If[f > ((d - b)/(c - a))(e - a) + b, y > ((d - b)/(c - a))(x - a) + b,
        y < ((d - b)/(c - a))(x - a) + b];
      Join @@ Join @@ (((List @@@
                          Map[ineq, Partition[poly, 3, 1, {1, 1}]], {x,
                            y}]]) /. rule1) /. rule2), poly]]

Note that the argument is a list of vertices in which the first and last are
not the same (in other words you do not repeat the starting vetex).

Here is an example:

polyg = {{1, 3}, {2, 5}, {4, 4}, {5, 2}};






Andrzej Kozlowski
Toyama International University

  • Prev by Date: Urgent Message Link --- Sample J/Link Projects
  • Next by Date: Re: ScatterPlot3D/Plot3D
  • Previous by thread: Re: Interior of a polygon
  • Next by thread: Re: Interior of a polygon