Saturday, June 22, 2024
HomeMatlabPolygons, Polyshapes and Puzzles » Cleve’s Nook: Cleve Moler on Arithmetic and...

Polygons, Polyshapes and Puzzles » Cleve’s Nook: Cleve Moler on Arithmetic and Computing

Till just lately, I knew nothing in regards to the polyshape object in MATLAB. Now I can use polyshape to simulate a unprecedented puzzle.



The Web page Artwork of Play, from some of us in San Diego, has nicely over two-hundred puzzles. Just lately, one in all their hottest puzzles, Mighty Cheese, caught my consideration. The concept is to maneuver the slices of plastic cheese round throughout the body so as to create a gap giant sufficient to carry the little plastic mouse. Nonetheless, once I final checked, Mighty Cheese was offered out. Not desirous to be dissuaded by the unavailability of the puzzle itself, and never realizing the answer, I got down to construct a simulator.

Not a T

I anticipated Mighty Cheese to be one thing just like the T-puzzle that I loved a number of years in the past. However, not like the T, the geometry of cheese can’t be modelled by easy rectangular patches. I wanted assist. Steve Eddins answered my plea and informed me about MATLAB’s “polyshapes”. That led to this weblog put up.

A slice of cheese

A “selfie” of a cheese slice gives an instance of a polyshape. It has curved boundaries and a gap. The MATLAB documentation for polyshape says this a polygon. In my mathematical world, polygons cannot have curved boundaries or holes. However, I assume that I’m being pedantic.

I started with this photograph of the Mighty Cheese puzzle.

puzzle = imread('Cheese_puzzle.png');

Two traces of code and the L*a*b colour mannequin discover the areas in photograph that appear like cheese.

[L,a,b] = imsplit(rgb2lab(puzzle));
masks = a > 30;

Steve supplied a operate that turns masks right into a polyshape object.

slice = my_polyshapes(masks);

An overloaded plot operate then generates the selfie from slice.

sliceplot = plot(slice, ...
    'facecolor',cheese_yellow, ...

My first resolution

I did not use AI or simulated annealing or every other trendy method to seek for an answer. I simply poked round whereas I used to be studying about polyshapes and programming my simulator. It was simply me and a actual mouse. No, not a actual actual mouse. You understand the type I imply.

Is that this resolution right?

I nearly made a weblog put up claiming that is the answer the designers of Mighty Cheese should have had in thoughts. However I wasn’t positive. My resolution made use of the white house across the exterior edges of the slices. How extensive are these gaps? I did not but have an actual bodily puzzle to measure tolerances.

Spoiler alert !

I’m positive glad now that I did not put up that “resolution”. It wasn’t right, and it wasn’t fairly.

This puzzle will not be as straightforward because it seems. In reality, the answer could be very exhausting to seek out and could be very elegant. If you wish to attempt to clear up it your self, cease studying this put up, bookmark this spot, and are available again later.

My second resolution

As I ought to have identified, this puzzle isn’t any secret to the Web It’s accessible for about $10 at many locations and YouTube presents a number of options. However I am glad that I did not see any of them till a couple of weeks in the past.

Once I made extra cautious measurements on “Cheese_puzzle.png” and had a extra correct mannequin to simulate, it grew to become clear that my valuable first resolution simply would not match.

A spherical peg in a sq. gap

No one stated that the mouse needed to match neatly right into a round gap with simply the correct diameter. When you understand that you just is perhaps on the lookout for a noncircular gap, you might be on the way in which to discovering the answer.


The important thing to the puzzle’s geometry is the purple axes on this image. They cross at proper angles at a degree within the heart gap on the tip of the protruding slice. The angle between the purple axes and the orange vertical/horizontal axes may be measured precisely on the photograph and all the pieces else follows. The angle is

theta = atand((y(b)-y(a))/(b-a)) = 11.62 levels


The masks that I used to be utilizing for my first resolution bought me began with polyshapes, however I ultimately deserted it. It’s straightforward to make a polyshape instantly from an inventory of factors across the boundary, like this.

The answer

The three holes within the authentic cheese slices don’t seem to serve any function. So, I’ve moved them and given them an essential function on this simulation. Mix the 2 triangular slices within the higher left right into a single slice. Rotate every of the ensuing 4 slices by an angle of 180-theta = 168.38 levels about its heart. The 4 right-angled corners from the central gap go to the corners of the puzzle whereas the outer corners type a central sq. simply giant sufficient to carry the mouse.

That’s actually elegant.

The place did this puzzle originate? What arithmetic was concerned in its design?

Software program

My code is right here: Mighty_Polyshape.m.

Printed with MATLAB® R2022b



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments