Perform geometric operations on polygons in C#

Geometric operations for polygons

This example contains a Polygon class that perform several useful geometric operations for polygons. The following list describes the key methods provided by the class. Click the links to see posts that describe the methods in greater detail.

To use the example, click to add points to the polygon. Then use function keys or the menu to perform the operations.

The “Point in Polygon” test is a bit odd because it uses the mouse’s current position as the point you want to test. If you use the menu item to perform the test, the point is wherever the menu item is. To test points without using the menu, press F3.

Note also that the Bounding Rectangle operation only works for convex polygons.

Download Example   Follow me on Twitter   RSS feed

This entry was posted in algorithms, geometry, graphics, mathematics and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

1 Response to Perform geometric operations on polygons in C#

  1. Find a smallest enclosing rectangle for a polygon in C#

    This program assumes that the polygon is convex and oriented counter-clockwise. This example demonstrates the Rotating Calipers method for finding a minimal bounding rectangle around the polygon. The algorithm is a bit tricky to visualize so you may want to run the program a few times while you read the following description. Each time you click the Step button, the program performs one iteration of the algorithm and examines one candidate bounding rectangle. First note that any minimal bounding rectangle has at least one edge that coincides with one of the polygon’s edges. The three other sides of …

Comments are closed.