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:
- 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!