2

I would like to know the total area and centroid of polygon above line after clipping. The polygon could be either convex or concave. But not self intersect.

I know there are great libraries for polygon clipping. However, I think my case is special(simpler) and I really want to increase the performance.

Anyone know what is the best algorithm to handle this case here. Any existing code would be great.

References: Polygon clipping by a line best describes my problem.

Community
  • 1
  • 1
  • 1
    The polygon could be either convex or concave. But not self intersect – user1585570 Dec 29 '12 at 19:14
  • ok, I will give you some hints on how to do this. If you're stuck, maybe I'll put some time into it. The algorithms to find area (http://alienryderflex.com/polygon_area/) and centroid (http://stackoverflow.com/questions/2792443/finding-the-centroid-of-a-polygon) of a non self-intersecting polygon are standard in computational geometry. They run in linear with respect to the # of vertices. You can modify these algorithms as follows to fit your need: when a side crosses the line, add a vertex equal to the intersection of the side with the line. Ignore all vertices below the line. – thang Jan 01 '13 at 18:59

1 Answers1

0

I think this link can show some light on your question. If you could provide us with what you had tried and the result that you had obtained, we would be able to give you better results.

Praveen Vinny
  • 2,372
  • 6
  • 32
  • 40
  • http://www.vbforums.com/showthread.php?421920-Polygon-clipping-by-a-line shows VB code which works pretty good. Just wondering is any C# code like that. I tried to convert the code manually however the array index used in VB code is 1 based while c# is 0 based. The program I converted doesn't work. – user1585570 Dec 29 '12 at 19:15