Last active
June 9, 2016 12:20
-
-
Save vmilev/f3d65780351a4bfe248d24f3bd0bd01c to your computer and use it in GitHub Desktop.
An extension method to calculate the surface area (in squared pixels) of a single polygon represented by a GraphicsPath object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class GraphicsPathExtensions | |
{ | |
public static float ComputeArea(this GraphicsPath graphicsPath) | |
{ | |
var points = graphicsPath.PathPoints.ToList(); | |
//Add the first point as the last in order to close the figure and compute area properly. | |
points.Add(points[0]); | |
return Math.Abs(points.Take(points.Count - 1).Select((p, i) => p.X * points[i + 1].Y - p.Y * points[i + 1].X).Sum()) / 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment