The integral of a function is the area connected by the boundaries, the curve of the function, and the x axis. Define one side of the rectangle as the x axis, then find the borders for the rest. There are many digital integration libraries in your chosen language.
EDIT: some difficulties in trying to illustrate with words ...
Assuming at least that the containing rectangle has an area larger than the sum of the regions of the subregions; and there is no requirement for a specific deterrence order:
- Contains the largest subregion first with ribs on the axes.
- Choose the next smaller subregion.
- Create a function (integral) to calculate the free area, as seen from each axis.
- With windows / limits equal to the length on the sides of the subregion (facing the axes), shift these windows along the axes from the origin.
- Create a function to find the free space bounded by the external levers of the cross formed by the windows as they slide along the axes. Space efficiency is in an area where free space is minimal (differentiation).
- Subregion rotates 90 degrees and repeats from step 3.
- Place the subregion in the position and place where it is most effective.
- Repeat step 2. Stop when sliding windows report negative.
free space for the entire domain (the allocated space overlaps the placeholder made by windows).
In theory, this will systematically attempt to squeeze in subregions. Sketch and pseudo code should follow if time permits.
source share