1

INTRO
I have an array of X/Y coordinates. This array generates an irregular polygon inside a square area of 128 x 128 pixels. So the value of the coordinates can be only a number from 0 to 127 (0,0 is the left top corner - 127,127 is the right bottom corner).
I have virtually divided this area in 4 small areas of 64 x 64 pixel each.

QUESTION
I would like to calculate 4 percentages where each percentage tells me how much the polygon is covering one of the small areas.

To be clear, I've this screenshot:

enter image description here

  • A, B, C and D area the small areas.
  • The red dots are the X/Y coordinates I have in an array.
  • The green area is the polygon virtually generated by the coordinates.

So, how to calculate the percentages of the areas covered by the polygon? For example, looking the screenshot, I would like to obtain that the A area is 40% covered, the B area is 5% covered, the C area is 15% covered, the D area is 80% covered.

Does anyone know a Javascript script that can perform this kind of calculation? Honestly, I'm not good in geometry!

  • Your question is rather broad. I suggest narrowing it down a little. Consider just asking how to calculate the area of a polygon. See this question https://stackoverflow.com/questions/24467972/calculate-area-of-polygon-given-x-y-coordinates – bhspencer Jul 27 '17 at 14:38
  • If you want I can translate the answer in to javascript for you. – bhspencer Jul 27 '17 at 14:39
  • Thank for your help. I've read the link you provided, but that post is how to calculate the area of a polygon that's not my question... however, any help is very appreciated. – Stevenworks Pictures Jul 27 '17 at 14:51
  • I'm not so sure how to do this with Javascript (OOP is awkward). How about some C# code? – meowgoesthedog Jul 27 '17 at 21:35
  • Your task is fundamentally in two parts. The first task is to divide your polygon into 4 polygons, One for each quadrant of your grid. Then you need to calculate the area of those 4 individual polygons. You can then divide each of those areas from the area of the quadrant and find the percent. – bhspencer Jul 27 '17 at 22:43
  • Draw the polygon into a 128x128 bitmap. Then, count the pixels set in overy one of the fourth 64x64 zones. – salva Aug 31 '17 at 12:12

0 Answers0