[comp.graphics] Point in polygon

larss@nada.kth.se (Lars Schylberg) (09/25/89)

Here's a cartographic problem that I have and that I would 
want to have an solution to.  My problem is that I want to label
areas and have to have a point that I know is inside a polygon.
I would be interested if someone had a piece of C-code or if
someone would want to discuss this in psuedo code manner.

I would want to input a polygon with x and y coordinates and
have it to return a point(x,y) that is surely inside the polygon 
even if the polygon is in horse shoe form or as L form.

point_in_pol( x_input_string, y_input_string, return_x, return_y);
int *x_input_string, * y_input_string;
int *return_x, *return_y;
{

}

It should work on this sample data set with north and east 
coordinates:


A 8          north  ^
 100 100       400  +   o-----------o
 400 100            |   |           |
 400 200            +   | o---------o
 150 200            |   | |
 150 300            +   | o---------o          
 400 300            |   |           |
 400 400            +   o-----------o
 100 400            |
                    +---+---+---+---+---+---+--->
                                   400          east
or this data of and L formed polygon.


A 6          north  ^
 100 100       400  +   o---o
 400 100            |   |   |
 400 200            +   |   |
 200 200            |   |   |
 200 400            +   |   o-------o          
 100 400            |   |           |
                    +   o-----------o
                    |
                    +---+---+---+---+---+---+--->
                                   400          east

The A stands for that the polygon describes an area and the number
after tells how many points the polygon has.

I know that Monmonier in his book Computer Assisted Cartography from
1982 has part of one solution where he uses plumb line intersections
to determine if a point is inside a polygon or not.  But then you need
a good guess for a starting point.  I'm sure there must be someone out
there have this solution and I don't want reenvent the wheel again by
writing this routine again.

Lars.

PS. this is also posted to the GIS AND DIGITAL CARTOGRAPHY NEWSLETTER  DS.

-- 
Lars Schylberg                        Email: larss@fmi.kth.se    (Internet)
Department of Photogrammetry                 larss@sekth.bitnet  (Bitnet)
Royal Institute of Technolgy          Tel.   +46 8 790 86 33     (office)
S-100 44  STOCKHOLM, SWEDEN           Fax.   +46 8 10 91 99