I need to calculate area of 2D polygon. (any shape, any size etc...)
I have only list of points, every points contains X and Y.
Polygons are in 2D block map, so:
But becouse I must use blocks/rectangles, then polygon looks more like that:
So must calculate this:
Block is in area, only if more than 50% of block is in polygon OR is corner/point of this polygon (like this arm at the bottom of image).
That possible to calculate that? without getting minimal, and maximal points, and checking every single block...
I only found some code for normal polygons:
public int getArea(List<BlockVector2D> blockPoints)
{
double result = 0;
int j = blockPoints.size() - 1;
for (int i = 0; i < blockPoints.size(); ++i)
{
result += (blockPoints.get(j).getBlockX() + blockPoints.get(i).getBlockX()) * (blockPoints.get(j).getBlockZ() - blockPoints.get(i).getBlockZ());
j = i;
}
return (int) Math.abs(result / 2);
}
But I have no idea how to do that using blocks-point...
Sorry for size and weird images... and my English.