c++ - Algorithm to assemble a simplified jigsaw puzzle where all edges are identified -
are there kind of algorithms out there can assist , accelerate in construction of jigsaw puzzle edges identified , each edge guaranteed fit 1 other edge (or no edges if piece corner or border piece)?
i've got data set here represented following structure:
struct tile { int a, b, c, d; }; tile[some_large_number] = ...;
each side (a, b, c, , d) uniquely indexed within puzzle 1 other tile match edge (if edge has match, since corner , border tiles might not).
unfortunately there no guarantees past that. order of tiles within array random, guarantee they're indexed 0 some_large_number. likewise, side uids randomized well. fall within contiguous range (where max of range depends on number of tiles , dimensions of completed puzzle), that's it.
i'm trying assemble puzzle in efficient way possible, can address completed puzzle using rows , columns through 2 dimensional array. how should go doing this?
the tile[]
data defines undirected graph each node links 2, 3 or 4 other nodes. choose node 2 links , set origin. 2 links node define x , y axes. if follow, say, x axis link, arrive @ node 3 links — 1 pointing origin, , 2 others corresponding positive x , y directions. can identify link in x direction, because take node 3 links (not 4).
in way can find pieces along 1 side until reach far corner, has 2 links. of pieces found far, untested links pointing in y direction. makes easy place next row of pieces. continue until pieces have been placed.
Comments
Post a Comment