This is a conceptually simple problem in 2D euclidean space.
Suppose you have a polyline in 2D euclidean space. How do you draw $n$ rectangles, of the form
$$ \lbrace (x, y) \in \mathbb{R} ^2: x_0 \leq x \leq x_1 \rbrace \cap \lbrace (x, y) \in \mathbb{R} ^2: y_0 \leq y \leq y_1 \rbrace $$
i.e. rectagles aligned with the axes, in such a way that the rectangles cover the polyline, but also minimise the total area?
Presumably you could take a higher and higher number of smaller and smaller rectangles covering the curve, each time getting a smaller total area - so there is no solution here.
But suppose there was a cost $\beta$ associated with adding a rectangle? Let me then state the problem more precisely:
Find natural number $n$ and rectangles $R_1, ... , R_n$ that cover the polyline, such that the cost function
$$ C= \alpha A + \beta n$$ is minimised, where A is the total area of the rectangles added up, and $\alpha$ and $\beta$ are fixed known positive (real) constants. $\alpha$ is a proportionality constant for the area, and $\beta$ is the "cost" of adding a rectangle.
This time increasing the number of rectangles $n$ indefinitely, makes the cost function indefinitely big. So it seems like there is a solution here.
For example, in the picture above, the three orange rectangles acheive a smaller cost that the single rectangle covering the whole line provided that the cost, $\beta$, of adding rectangles is not too high. The solution would be, for a given line, the number $n$ together with the $4 \times n$ real numbers required to define the $n$ rectangles.
Is there an analytical solution here? A numerical solution?
In practice I'm looking for an algorithm that can do "pretty well" at minimising the cost!
Context: the real problem I have is calling an API for road data within a certain bounding box on earth. The road data I get needs to cover the given polyline, but the easy call to make (the bounding box covering the whole line) is too expensive, and is simply too much data when the polyline is very long.
