I have an application where the user can drag their images (.pngs) around on a virtual table. The images are of shapes - mostly regular polygons, but some jigsaw pieces, tetris blocks, et cetera.
I want the shapes, as they are being dragged, to snap to one another like two jigsaw pieces might.(Like in MS Word "Snap to grid")
How might I accomplish this?
Constraints:
Speed: This will be either happening as the user drags the image, or at the point of dropping. Therefore the algorithm must be fast (realtime). Any number of images may be being dragged, and there may be any number of stationary images to snap to.
No further user input: There should be no requirement for the user to do anything beyond opening the image file, and drag the images.
Possibilities:
Use some sort of concave hull algorithm + simplifaction, then match edge lengths. The issue with this is that the user's edges can't be guaranteed to be that straight/well defined.
Use a laplace transform on the transparency component of the image (To edge-detect), then treat those regions as being positively and negatively charged, and use a physical simulation to find how they snap together. Limitation: Speed, tuning.
I am currently just assuming the images are one of the regular tessellations: Rectangle, triangle or hexagon, and working from there. But i'd prefer something which works with other shapes.