The values of a function of two variables z = f (x, y), where x, y, z take integer values are stored in sql db. Calculate (appoint) the largest surface area of the flat. By ‘flat area’ we mean an area about which for each pair of x and y lying inside the area about the value of the function is constant (z = const).
I have already tried to use this flood fill algorithm, but I am not sure if this is the right way. e.g. if I have pairs(x,y) as follows: (0,0),(0,2),(2,0),(2,2) for which z equals to 5(z=const) and have point (1,1) where z=1 – how should I compute “flat area”?
3
The main question is if your “flat area” has to be convex or not.
If it can be non-convex then flood fill algorithm will work fine, and your example area can be treated as the flat area.
If it has to be convex then the answer from below question will work
https://stackoverflow.com/questions/7332065/what-is-the-best-algorithm-to-find-the-largest-black-convex-area-in-an-image
Use flood fill to identify flat regions with no holes. For each one, solve the problem for that region, remember the answer, identify an adjacent flat region (if any), alter the current region to have the adjacent region’s altitude, rinse, lather, repeat. Subtracting the area of the altitude 1 region from the area of the enclosing altitude 5 region is straightforward.