This wiki has been archived and made read-only.
For up-to-date information about TkkrLab and it's projects please visit our main website at tkkrlab.nl.

Difference between revisions of "Fractal Jigsaw Puzzle"

From

Jump to: navigation, search
(Select on used pieces)
(Select on used pieces)
Line 101: Line 101:
 
two pieces with the same shape. It makes sense to use both options, as long
 
two pieces with the same shape. It makes sense to use both options, as long
 
as the value for -sup_occ is larger than -max_occ.
 
as the value for -sup_occ is larger than -max_occ.
 +
 +
This function will output the names (numbers) of the pieces that are used
 +
in the design. The names are sorted from low to high. This allows for the
 +
output to be piped into the following command:
 +
 +
  sort | uniq -c | sort
 +
 +
Which will result in a list of designs with a low number of solutions to
 +
a high number of solutions. If one want to make an easy puzzle, one should
 +
select for a design that has many solutions. Not all designs with a low
 +
number of solutions are hard, because it could be the case that they
 +
contain a number of large pieces that could only be placed at a few locations,
 +
thus quickly reducing the number of possible places for the remaining pieces.
  
 
=== Filter solutions ===
 
=== Filter solutions ===

Revision as of 21:03, 11 January 2017

The Fractal Jigsaw Puzzle can be made with a Laser Cutter and is based on an idea by Oscar van Deventer, which he shows in this video. The puzzle can be ordered from Laser Exact.

This page describes software to produce your own Fractal Jigsaw puzzles, possibly resulting in a better design than the one used by Van Deventer.

Original design

It seems that the design by Van Deventer is taken from Bridged Polyamonds. On this mathpuzzle page there is a link to the design of the puzzle with a matching colouring of the pieces. One could try to import this image in Inkscape and try to vectorize the image, but it is doubtfull whether this will lead to a good result.

Program

The program (written in C++) combines seven different functions that can be used to generate designs, to filter interesting designs, to visualize the designs, and to produce Scalable Vector Graphics (SVG) files that be imported into Inkscape.

To find designs the program makes use of an Exact Cover solver. The first two functions of the program can be used to generate an input file for the solver. The output from the Exact Cover solver can be processed with the third function.

Generating input for Exact Cover solver

The two first functions of the pianofrac program can be used to generate input for the Exact Cover solver.

 pianofrac gen_ec_hc [-with_name]
 pianofrac gen_ec [-con] [-range=n,n-n,n-] [-with_name]

The first function (gen_ec_hc) generates input based on a hard coded set of pieces. The -with_name option will add names to the lines. The names actually consists of an unique number for each piece. The names are needed for the select function (explained below). With the second function (gen_ec), one can specify a range of sizes for the pieces. The -con option can be used to also little connection dots that are needed for some solutions. The function gen_ec with the arguments "-con -range=2-3" is equal to function gen_ec_hc. If high numbers are used in the -range option, the function can produce a very large output file. The use of the -with_name option could cause the program to slowdown and use large amounts of memory.

Each line of the generated output represent one possible placement of a piece, represented by a binary vector using 0 and 1 followed by a space and a description of the placement. Each possible design of a puzzle can be represented by a (small) selection of the lines such that in each column there is exactly one 1 and only 0's in all other lines. If this is the case, it means that the piece placements do not overlap and cover all locations.

Normalizing results from Exact Cover solver

The Exact Cover solver will produce a file with one solution per line, where each solution is represented by the names of the the selected piece placement. Because of the triangle nature of the puzzle, there are always six solutions that are equivalent with respect to rotations and mirroring. The function normalize with the option -minimal can be used to remove all 'double' solutions and thus reduce the file of solutions with a factor six. If the -minimal options is not used, the solutions will all be normalized, causing each solution to appear six times in the solution. (One could use "sort -u" to achieve the same effect as using the -minimal option.)

 pianofrac normalize [-minimal]

The Exact Cover solver that accepts the input and produces output fit for this function can be found here in the form of a C++ program. Because this program reads the input from the standard input and produces output to the standard output, for example, the following pipe command can be used:

 pianofrac gen_hc -con -range=2-5 | ExactCover | pianofrac normalize -minimal

Select on used pieces

One could take a random line from the output produced from the Exact Cover solver and feed this as input to the function to produce an SVG file, but this might result in a design that does not have nice properties. For example, because it has a lot of small pieces or some large pieces. Or because it has many pieces of the same shape. The following function can be used to remove such designs. The function requires that the pieces have a name, which is used to identify pieces with the same shape. (A future version of the program may drop this restriction.) The function is called in the following manner:

 pianofrac used_pieces [-max_occ=n] [-sup_occ=n] [-max=n] [-min=n]

The -min and -max options specify the minimum and maximum number of pieces (value included) that a design should have. The option -max_occ restricts the maximum number of times that a piece of the same shape may occur. And the option -sup_occ restricts the total number of pieces that have the same shape. If for example -max_occ=2 is used, it could still be the case that for each piece there is another piece with the same shape. (This is only possible if there is an even number of pieces and that for each shape there are two pieces in the design.) With the option -sup_occ=2 there could be at most two pieces with the same shape. It makes sense to use both options, as long as the value for -sup_occ is larger than -max_occ.

This function will output the names (numbers) of the pieces that are used in the design. The names are sorted from low to high. This allows for the output to be piped into the following command:

 sort | uniq -c | sort

Which will result in a list of designs with a low number of solutions to a high number of solutions. If one want to make an easy puzzle, one should select for a design that has many solutions. Not all designs with a low number of solutions are hard, because it could be the case that they contain a number of large pieces that could only be placed at a few locations, thus quickly reducing the number of possible places for the remaining pieces.

Filter solutions

Coming soon

 pianofrac filter <pieces>

Print solution

Coming soon

 pianofrac print

Generate SVG

Coming soon

 pianofrac svg [-border_rad=n] [-border_d=n] [-depth=n]
               [-colour=n] [-stroke_width=n] [-side_length=n]

Result

For those people who are too lazy to download the program, compile it, and experiment with it (with lots of trial and error) we give a ready design consisting of nine pieces pieces.

External Links

FractalJigsawPuzzle on GitHub

The original blog entries on which this page is based: