mikepound / cubes

This code calculates all the variations of 3D polycubes for any size (time permitting!)
MIT License
163 stars 43 forks source link

Potential new method for generating unique strings to describe the shapes. #26

Closed Robert-trober closed 12 months ago

Robert-trober commented 1 year ago

I've only tested the method that I've come up with in 2 dimensions, but it seems to work for the small extents to which I've tested it, though I myself have little coding knowledge and don't know how to write a programme to test it further. The method is as follows: For each square in the polyform you will generate a list which relates its position to all other squares in the polyform (by a method which I will describe shortly). Then you add together all of the lists that you generated for each of the squares ex: (1,3,7)+(0,2,3) = (1,5,10) and that summed list will be unique to the shape from which it was generated, this holds through any transformation or rotation because it depends on the relative points of the shape and not the position of the shape (and in the manner in which I've done it, separate lists will be generated for shapes which are right-handed and left-handed).

The method for generating the strings for each square is this: You move outwards one space from each face of the square you are checking. Then, in these four adjacent squares, you add up how many of those four spaces are parts of the shape and make that sum, anywhere from 0 to 4, the first number in the list, then you move clockwise and check the four spaces at the corners of the square and make that total the second number in the list. After that you check all of the spaces two spaces away from the faces of the square you're doing, then you rotate the spaces checked clockwise until you've moved to a position that you've checked before wherein you move even further from the faces of the square. You continue checking the spaces of these successively larger rings until you've accounted for all of the squares in the shape by which you have generated a string describing the relative position of a square to all other squares in the shape ex: (1,0,1) (the example is from an end of a three long and one high polyform).

I add everything at the end so that it doesn't matter what order you do it in and I check four spaces at a time because then you'll get the same numbers no matter the rotation of the object. I've also attempted to attach an image to visually explain the square checking sequence.

IMG_20230718_134756160

Robert-trober commented 1 year ago

I've created a crude programme to do what I've described above, It only functions in 2 dimensions and you have to manually input the shapes. https://gist.github.com/Robert-trober/fb4d2904ac48aa1ff170bb77903beaf4