{"id":9491,"date":"2022-12-09T21:41:01","date_gmt":"2022-12-10T02:41:01","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=9491"},"modified":"2023-04-21T15:30:50","modified_gmt":"2023-04-21T19:30:50","slug":"color-cube-meets-rubiks-cube","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2022\/12\/09\/color-cube-meets-rubiks-cube\/","title":{"rendered":"Color Cube Meets Rubik&#8217;s Cube"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>I have made a half dozen blog posts about <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2022\/09\/05\/rubiks-cube-superflips-and-gods-number\/\">Rubik's Cube<\/a> so far this year.  And, during the MATLAB Central Mini Hack in October, I resurrected an old code about the <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2022\/10\/21\/an-interactive-version-of-colorcubes\/\">Color Cube<\/a>.  Now, a combination of the two, Rubik\/Color Qube, creates an elegant tool for investigating <i>Matrices in Action<\/i>.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#c4ab2cc4-7c62-45b6-b8d6-b58e96dd8c07\">Opening<\/a><\/li><li><a href=\"#3426fb76-f361-4a32-b165-f771bba3fb03\">Rubik and Color<\/a><\/li><li><a href=\"#28b692dc-0d85-4c30-905e-300857741d5c\">Color Qube<\/a><\/li><li><a href=\"#f9469ecf-8b7e-41d3-8f47-ac23128f5f7d\">Rotations<\/a><\/li><li><a href=\"#eb4d3e17-82e6-4b1e-b966-c75328d89269\">n-by-n-by-n<\/a><\/li><li><a href=\"#715fe67d-21d9-46c4-a0b5-b2864db8776f\">2-by-2-by-2<\/a><\/li><li><a href=\"#b23519d3-2aa0-46a3-9160-90f256981b7e\">Software<\/a><\/li><\/ul><\/div><h4>Opening<a name=\"c4ab2cc4-7c62-45b6-b8d6-b58e96dd8c07\"><\/a><\/h4><p>Here is the opening screen shot of Rubik\/Color Qube, one of the most elaborate MATLAB programs that I have ever written.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/screen_shot1.png\" alt=\"\"> <\/p><h4>Rubik and Color<a name=\"3426fb76-f361-4a32-b165-f771bba3fb03\"><\/a><\/h4><p>There are two modes, <tt>rubik<\/tt> and <tt>color<\/tt>. In <tt>rubik<\/tt> mode, the large cube is formed from 27 identical copies of a single small <i>cubelet<\/i>.  The six cubelet faces have six different colors.  Red, white and blue are visible initially.  Orange, yellow and green become visible as the faces are rotated.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/rubik.gif\" alt=\"\"> <\/p><p>In <tt>color<\/tt> mode, the large cube is formed from 27 <i>cubelets<\/i>, each with a different solid color.  Three of the corner cubelets are the primary colors in the RGB color model -- red, green and blue.  Three more corners are the complementary cyan, magenta and yellow. White and black complete the list of corners.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/color.gif\" alt=\"\"> <\/p><h4>Color Qube<a name=\"28b692dc-0d85-4c30-905e-300857741d5c\"><\/a><\/h4><p>All of the familiar Rubik's moves are available in <tt>color<\/tt> mode. Here is a screen shot after a few rotations.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/screen_shot2.png\" alt=\"\"> <\/p><h4>Rotations<a name=\"f9469ecf-8b7e-41d3-8f47-ac23128f5f7d\"><\/a><\/h4><p>Rotation matrices defined by this <tt>Rk<\/tt> function are the basic mathematical tool employed by <tt>Qube<\/tt>.  The animation provides a detailed look at the action produced by the F key, counter-clockwise rotation of the Front face.  This is the y-axis, case 2 in <tt>Rk<\/tt>.  The detail is provided by taking <tt>d = 0:3:90<\/tt>, so there are 30 steps of 3 degrees.<\/p><pre class=\"language-matlab\"><span class=\"keyword\">function<\/span> R = Rk(axis,d)\r\n    <span class=\"comment\">%  Rk(axis,d), Rotation by d degrees about the x-, y-, or z-axis.<\/span>\r\n    c = cosd(d);\r\n    s = sind(d);\r\n    <span class=\"keyword\">switch<\/span> axis\r\n        <span class=\"keyword\">case<\/span> 1, R = [ 1  0  0\r\n                      0  c  s\r\n                      0 -s  c ];\r\n        <span class=\"keyword\">case<\/span> 2, R = [ c  0  s\r\n                      0  1  0\r\n                     -s  0  c ];\r\n        <span class=\"keyword\">case<\/span> 3, R = [ c  s  0\r\n                     -s  c  0\r\n                      0  0  1 ];\r\n    <span class=\"keyword\">end<\/span>\r\n    fmat = findobj(<span class=\"string\">'tag'<\/span>,<span class=\"string\">'fmat'<\/span>);\r\n    <span class=\"keyword\">if<\/span> ~isempty(fmat)\r\n        fmat.String = mat3(R);\r\n    <span class=\"keyword\">end<\/span>\r\n<span class=\"keyword\">end<\/span>\r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/dpm3.gif\" alt=\"\"> <\/p><h4>n-by-n-by-n<a name=\"eb4d3e17-82e6-4b1e-b966-c75328d89269\"><\/a><\/h4><p><tt>Qube<\/tt> generalizes the classic 3-by-3-by-3 Rubik's Cube to n-by-n-by-n cubes for any n.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/n_by_n.gif\" alt=\"\"> <\/p><h4>2-by-2-by-2<a name=\"715fe67d-21d9-46c4-a0b5-b2864db8776f\"><\/a><\/h4><p>The 2-by-2-by-2 cubes are good starting points for investigation of mathematical properties.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/2_by_2.png\" alt=\"\"> <\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/2_by_2_color.png\" alt=\"\"> <\/p><h4>Software<a name=\"b23519d3-2aa0-46a3-9160-90f256981b7e\"><\/a><\/h4><p><tt>Qube<\/tt> is available as a self-extracting MATLAB archive at this link, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/Qube_mzip-2.m\">Qube_mzip.m<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_ce9c453c88254608ad0e691ca4711df7() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='ce9c453c88254608ad0e691ca4711df7 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' ce9c453c88254608ad0e691ca4711df7';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2022 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_ce9c453c88254608ad0e691ca4711df7()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2022b<br><\/p><\/div><!--\r\nce9c453c88254608ad0e691ca4711df7 ##### SOURCE BEGIN #####\r\n%% Color Cube Meets Rubik's Cube\r\n% I have made a half dozen blog posts about\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2022\/09\/05\/rubiks-cube-superflips-and-gods-number\/\r\n% Rubik's Cube> so far this year.  And, during the MATLAB Central Mini \r\n% Hack in October, I resurrected an old code about the \r\n% <https:\/\/blogs.mathworks.com\/cleve\/2022\/10\/21\/an-interactive-version-of-colorcubes\/\r\n% Color Cube>.  Now, a combination of the two, Rubik\/Color Qube,\r\n% creates an elegant\r\n% tool for investigating _Matrices in Action_.\r\n\r\n%% Opening\r\n% Here is the opening screen shot of Rubik\/Color Qube, one of the most\r\n% elaborate MATLAB programs that I have ever written.\r\n%\r\n% <<screen_shot1.png>>\r\n%\r\n\r\n%% Rubik and Color\r\n% There are two modes, |rubik| and |color|.\r\n% In |rubik| mode, the large cube is formed from 27 identical copies\r\n% of a single small _cubelet_.  The six cubelet faces have six different\r\n% colors.  Red, white and blue are visible initially.  Orange, yellow\r\n% and green become visible as the faces are rotated.\r\n%\r\n% <<rubik.gif>>\r\n%\r\n% In |color| mode, the large cube is formed from 27 _cubelets_,\r\n% each with a different solid color.  Three of the corner cubelets are the\r\n% primary colors in the RGB color model REPLACE_WITH_DASH_DASH red, green and blue.  Three\r\n% more corners are the complementary cyan, magenta and yellow.\r\n% White and black complete the list of corners.\r\n%\r\n% <<color.gif>>\r\n%\r\n\r\n%% Color Qube\r\n% All of the familiar Rubik's moves are available in |color| mode.\r\n% Here is a screen shot after a few rotations.\r\n%\r\n% <<screen_shot2.png>>\r\n%\r\n\r\n%% Rotations\r\n% Rotation matrices defined by this |Rk| function are the basic \r\n% mathematical tool employed by |Qube|.  The animation provides a detailed \r\n% look at the action produced by the F key, counter-clockwise rotation of\r\n% the Front face.  This is the y-axis, case 2 in |Rk|.  The detail is \r\n% provided by taking |d = 0:3:90|, so there are 30 steps of 3 degrees.\r\n% \r\n%   function R = Rk(axis,d)\r\n%       %  Rk(axis,d), Rotation by d degrees about the x-, y-, or z-axis.\r\n%       c = cosd(d); \r\n%       s = sind(d);\r\n%       switch axis\r\n%           case 1, R = [ 1  0  0  \r\n%                         0  c  s\r\n%                         0 -s  c ];\r\n%           case 2, R = [ c  0  s  \r\n%                         0  1  0\r\n%                        -s  0  c ];\r\n%           case 3, R = [ c  s  0  \r\n%                        -s  c  0\r\n%                         0  0  1 ];\r\n%       end\r\n%       fmat = findobj('tag','fmat');\r\n%       if ~isempty(fmat)\r\n%           fmat.String = mat3(R);\r\n%       end\r\n%   end\r\n%\r\n%\r\n% <<dpm3.gif>>\r\n%\r\n\r\n%% n-by-n-by-n\r\n% |Qube| generalizes the classic 3-by-3-by-3 Rubik's Cube\r\n% to n-by-n-by-n cubes for any n.\r\n%\r\n% <<n_by_n.gif>>\r\n%\r\n\r\n%% 2-by-2-by-2\r\n% The 2-by-2-by-2 cubes are good starting points for investigation\r\n% of mathematical properties.\r\n%\r\n% <<2_by_2.png>>\r\n%\r\n% <<2_by_2_color.png>>\r\n%\r\n\r\n%% Software\r\n% |Qube| is available as a self-extracting MATLAB archive at this link,\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/Qube_mzip-2.m Qube_mzip.m>.\r\n##### SOURCE END ##### ce9c453c88254608ad0e691ca4711df7\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/two_X_two.gif\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction--><p>I have made a half dozen blog posts about <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2022\/09\/05\/rubiks-cube-superflips-and-gods-number\/\">Rubik's Cube<\/a> so far this year.  And, during the MATLAB Central Mini Hack in October, I resurrected an old code about the <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2022\/10\/21\/an-interactive-version-of-colorcubes\/\">Color Cube<\/a>.  Now, a combination of the two, Rubik\/Color Qube, creates an elegant tool for investigating <i>Matrices in Action<\/i>.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2022\/12\/09\/color-cube-meets-rubiks-cube\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":9548,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,23,6,47,39],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/9491"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=9491"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/9491\/revisions"}],"predecessor-version":[{"id":10341,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/9491\/revisions\/10341"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/9548"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=9491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=9491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=9491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}