Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
XML
Point in Polygon
Write a function to determine whether a given point in the plane lies INSIDE, ON, or OUTSIDE the boundary of a polygon.
Use Ray casting algorithm to implement the function.

The results of the program should look exactly like the above screenshot.

The functions signature will look like this:
/// <summary>
        /// Determine whether the Point lies inside or on the boundary of the Polygon
        /// </summary>
        /// <param name="p">Point to be determined</param>
        /// <param name="ptPolygon">Points of the polygon</param>
        /// <returns>True if the Point lies inside, False if it lies outside on the boundary of the Polygon, otherwise null if the point lies on the boundary</returns>
        static Nullable<bool> IsPointInPolygon(System.Windows.Point p, System.Windows.Media.PointCollection ptPolygon)

Use the following statements to generate the points of polygon and points to be determined:
        System.Windows.Media.PointCollection pointsOfPolygon =
            new System.Windows.Media.PointCollection(new Point[] {
                new Point(1,6),
                new Point(6,11),
                new Point(8,8),
                new Point(7,12),
                new Point(10,12),
                new Point(10,10),
                new Point(12,10),
                new Point(13,15),
                new Point(15,7),
            });

        System.Windows.Point[] points =
            new Point[] {
                new Point(3,8),
                new Point(6,8),
                new Point(7,10),
                new Point(7,11),
                new Point(8,7),
                new Point(8,8),
                new Point(8,10),
                new Point(8,15),
                new Point(10,8),
                new Point(10,11),
                new Point(10,15),
                new Point(11,10),
                new Point(13,7),
                new Point(13,8),
                new Point(13,10),
                new Point(15,10),
            };
Posted
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 0:45am    
Would be a good question, but you just copied a question someone else gave you, did not even take a labor to re-formulate it. Bad!
--SA

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900