Background:
I am scrambling to figure out the optimization algorithm to build sprite image, which is essentially a big container rectangular image, with multiple rectangular images.
I have found an elaborated article to solve this problem. But to incorporate more parameters to the mix requires good grasp on mathematical aspect of the solution. Bottom line; I am interested in mathematical solution of this problem (perhaps with scary equations).
The Problem:
Algorithm: Given multiple rectangular images, with uneven dimensions; width and heights (in pixel). Our goal is to merge all the images on an empty transparent canvas without overlapping.
Mathematics: Find the (x, y) start-point coordinate of each rectangle, where to begin drawing on the resultant rectangle (canvas); the final sprite image.
The parameters:
- Collections of images to merge: with meta information, viz; Height, Width, Resolution etc.
- Aspect ratio to maintain for sprite image.
- Default value:
any(that is; enumeration for one's complement ~0); flexible for the most optimized results. - Could be a x-y pair:
4:3,6:3etc.
- Default value:
- Gutter size (default -> 1 pixel): spacing between adjacent images and edges of the sprite.
Questions:
Which domain is most suitable to solve this problem: Matrix, Calculus or Graph Theory?
What area optimization techniques would entertain the parameters like desired aspect ratio (as mentioned previously its an optional parameter, defaulted to
any)?Can it be solved with Calculus' differentiation (perhaps using Newton Raphson method)?