[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1937.0. "IN OR OUT ?" by TAVIS::SHIRAN () Sun Feb 19 1995 02:51

    Consider a POLYGON with N points of any shape.
    you are given the coordinates (x,y) of all points.
    
    you are given the coordinates of another point in the same plane
    (not one of the N points of the polygon).
    
    how would you find out (without drawing) if the extra point
    is within the polygon ?
    
T.RTitleUserPersonal
Name
DateLines
1937.12D methodsAZUR::DESOZAJean-Pierre,Sophia-Antipolis 828-5559Mon Feb 20 1995 03:2017
If you are solving a 2D geometry problem here are two methods.

The first method is based on the angles. When a point is inside a polygon,
the sum of angles from that point to each 2 contiguous vertices is 2*Pi.
I never implemented that method. 

The second method is based on intersections:
An arbitrary straight line starting from this point (and in the same plane
as the polygon) will intersect the polygon:
- An ODD number of times if the point is inside the polygon.
- An EVEN number of times if the point is outside.
Warnings: 
1) You must orient the polygon and define clearly what "Inside" and
"Outside" means. The polygon could be the outline of a hole.
2) "Arbitrary" is also an issue. You may draw a line from the given point
to a vertex, find only one intersection point and conclude the point is inside. 
I already implemented that method successfully.
1937.2HERON::WS1026::BLOMBERGMon Feb 20 1995 11:5011
    
    A polygon is not uniquelydefined by the vertices. Different polygons
    may have the same vertices. A polycon can be defined by the edges,
    e.g., as linear forms
    
    	L(j)(x,y) = 0; j=1..N
    
    and with the proper choice of signs can the "interior" be defined
    as all the points for which
    
    	L(j)(x,y) > 0; j=1..N
1937.3HANNAH::OSMANsee HANNAH::IGLOO$:[OSMAN]ERIC.VT240Mon Feb 20 1995 15:505
Or, consider what you're really trying to do.  Maybe you can do it without
knowing whether the point is inside or outside the polygon !

/Eric