algorithm - How to get arbitrary shapes, defined by images with transparency, to snap to one another such that there is no seam between the two? -


I have an application where the user can drag his images (.png) onto the virtual table. The images are of size - mostly regular polygon, but some saw pieces, Tetris blocks, et al.

I want the shapes, because they are pulling, to draw each other like a picture of two rows. (Like MS Word "Snap To Grid")

How can I complete this?

Obstacles:

Speed: This will be happening either because the user leaves the image, or at the time of quitting. Therefore the algorithm should be intense (real time). Any number of images can be dragged, and there can be any static picture to snap.

No other user input: There should be no need for the user to do anything except opening the image file, and drag images.

Possibilities:

Use some sort of hull algorithm + simplicity, then match the length of the edge, with this issue, the point is that the edges of the user are straight / well Defined from can not be guaranteed.

Use a lapless transformation on the transparency component of the image, then those areas are being charged positively and negatively, and using physical simulations, find out that they How to snap together. Limitations: Speed, tuning.

I currently only believe that the images are hidden regularly: rectangles, triangle or hexagon, and are working from there. But I like something that works with other shapes.

Each size should have some reference points and one (possibly curved) line between them. If you need to snap two sizes then the first thing to match those reference points will be the easiest, and if they match, then you can match the lines between each pair of two digits. The lines should be coded in such a way that you do not need some mathematical operation to match them, just match the parameters of the lines.

Take Tetris blocks. Each block has reference points on the grid crossing, and each line has a straight line, a square shape has 8 digits and lines, and the L shape has 10 digits / lines, the first match reference points, and then if on each shape the match There are lines between the same points (and take line orientation in relation).

Take the jigsaw puzzle usually you have 4 digits / lines, but the lines decrease arbitrarily, you can actually use mathematical curves , But you can also make some jigsaw curve indicator for each curve. When you try to match the first two pieces, you match the reference points, and then you compare only the curve by comparing their index to both their line orientation and their index.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -