Developing For .NET

Real World .NET Methods, Tricks, and Examples

PolygonF

A class that wraps a PointF[] representing a Polygon. The class members include:

  • RectangleF Bounds
  • float MinimumX
  • float MaximumX
  • float Minimum Y
  • float Maximum Y
  • int NumberOfPoints
  • bool IsInBounds(PointF pt)
  • bool Contains(PointF pt)
  • PointF CenterPointOfBounds
  • PointF CenterPoint // Not yet implemented
  • decimal Area

IsInBounds returns true if the PointF is within the Rectangular Bounds of the Polygon. Contains returns true if the PointF is actually within the Polygon’s borders.

The class includes both the PolygonF and Polygon classes. Polygon is identical to PolygonF except that it works with an array of Point objects and return ints instead of floats.

First introduced on the blog under Testing to see if a Point is within a Polygon.

DOWNLOAD

5 comments

5 Comments so far

  1. sungil October 19th, 2008 10:18 am

    THANK YOU

  2. Joel October 20th, 2008 1:32 pm

    You’re welcome!

  3. Patricio Vidal December 3rd, 2008 12:00 am

    Thank you for your class. I’m using it on my Open Source project. I credited you by adding this blog link on our About dialog.
    Regards,
    Patricio.

  4. Joel December 3rd, 2008 10:51 am

    Thanks Patricio, I hope it is helpful!

  5. Dean December 18th, 2009 5:00 pm

    Thanks – This code is great!

Leave a reply

Spam Protection by WP-SpamFree