I work with geospatial forms and look at the centroid algorithm here,
http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon
I implemented code in C #, like this one (which has just been adapted),
Looking for the center of gravity of a polygon?
class Program { static void Main(string[] args) { List<Point> vertices = new List<Point>(); vertices.Add(new Point() { X = 1, Y = 1 }); vertices.Add(new Point() { X = 1, Y = 10 }); vertices.Add(new Point() { X = 2, Y = 10 }); vertices.Add(new Point() { X = 2, Y = 2 }); vertices.Add(new Point() { X = 10, Y = 2 }); vertices.Add(new Point() { X = 10, Y = 1 }); vertices.Add(new Point() { X = 1, Y = 1 }); Point centroid = Compute2DPolygonCentroid(vertices); } static Point Compute2DPolygonCentroid(List<Point> vertices) { Point centroid = new Point() { X = 0.0, Y = 0.0 }; double signedArea = 0.0; double x0 = 0.0;
The problem is that this algorithm, when I have this form (form L),
(1.1) (1.10) (2.10) (2.2) (10.2) (10.1) (1.1)
This gives me the result (3.62, 3.62). This is normal, except that the point is out of shape. Is there any other algorithm that takes this into account?
Basically, a person will draw a figure on a map. This shape can span several roads (it could be an L-shape), and I want to work out the center of the figure. This means that I can determine the name of the road at this moment. It doesn't make sense to me if he were out of shape if they drew a long skinny L-shape.
source share