{"id":7488,"date":"2021-10-03T10:42:11","date_gmt":"2021-10-03T14:42:11","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=7488"},"modified":"2021-10-03T10:57:10","modified_gmt":"2021-10-03T14:57:10","slug":"the-computer-graphics-matrix-and-a-cube","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2021\/10\/03\/the-computer-graphics-matrix-and-a-cube\/","title":{"rendered":"The Computer Graphics Matrix and a Cube"},"content":{"rendered":"\r\n<div class=\"content\"><!--introduction--><p>Use a cube instead of the Utah Teapot in <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2021\/10\/03\/the-matrix-at-the-heart-of-computer-graphics\">my previous post<\/a>.  I was pleasantly suprised by the final screen shot.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#4eada8ec-439f-4cac-8b45-3fe3fd408f92\">RGB cube<\/a><\/li><li><a href=\"#daddfe12-7ca2-4aa7-8783-3177514aa998\"><tt>Rz<\/tt><\/a><\/li><li><a href=\"#1c0d0998-470e-4724-98df-4512238b13af\"><tt>Rx*Rz<\/tt><\/a><\/li><li><a href=\"#4487102a-b974-430f-8841-bd86e26a7657\"><tt>Rz*Rx<\/tt><\/a><\/li><li><a href=\"#d453fde3-b7e4-4b5b-96b5-71a70a67d480\"><tt>Ry<\/tt><\/a><\/li><li><a href=\"#4587fa81-d52a-4258-96c8-f962fbf2793b\"><tt>Tx<\/tt><\/a><\/li><li><a href=\"#3fc8c994-4f4b-4741-ac68-fa11ed0736eb\"><tt>Sxyz<\/tt><\/a><\/li><li><a href=\"#8210ccf3-d9e8-49d4-8a66-7b616ec84ceb\">All together<\/a><\/li><li><a href=\"#6e107ea8-f305-449a-acf8-361164c3638e\">Clipped<\/a><\/li><li><a href=\"#d6b980b4-ef62-4483-a9bb-3eb045f04471\">Which?<\/a><\/li><\/ul><\/div><h4>RGB cube<a name=\"4eada8ec-439f-4cac-8b45-3fe3fd408f92\"><\/a><\/h4><p>Three faces of our cube are colored with red, green and blue. The opposite faces have the complentary colors, cyan, magenta and yellow.  Initially, only the yellow face is visible.<\/p><pre class=\"codeinput\">    Cube = grafix(<span class=\"string\">'6'<\/span>,<span class=\"string\">'rgb'<\/span>);   <span class=\"comment\">% Platonic solid with 6 faces.<\/span>\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_01.png\" alt=\"\"> <h4><tt>Rz<\/tt><a name=\"daddfe12-7ca2-4aa7-8783-3177514aa998\"><\/a><\/h4><pre class=\"codeinput\">    Rz = R_z(45);\r\n    apply(Cube,Rz)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_02.png\" alt=\"\"> <h4><tt>Rx*Rz<\/tt><a name=\"1c0d0998-470e-4724-98df-4512238b13af\"><\/a><\/h4><pre class=\"codeinput\">    Rx = R_x(60);\r\n    M = Rx*Rz;\r\n    apply(Cube,M)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_03.png\" alt=\"\"> <h4><tt>Rz*Rx<\/tt><a name=\"4487102a-b974-430f-8841-bd86e26a7657\"><\/a><\/h4><pre class=\"codeinput\">    M = Rz*Rx;\r\n    apply(Cube,M)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_04.png\" alt=\"\"> <h4><tt>Ry<\/tt><a name=\"d453fde3-b7e4-4b5b-96b5-71a70a67d480\"><\/a><\/h4><pre class=\"codeinput\">    Ry = R_y(-120);\r\n    apply(Cube,Ry)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_05.png\" alt=\"\"> <h4><tt>Tx<\/tt><a name=\"4587fa81-d52a-4258-96c8-f962fbf2793b\"><\/a><\/h4><pre class=\"codeinput\">    Tx = T_x(2.5);\r\n    apply(Cube,Tx)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_06.png\" alt=\"\"> <h4><tt>Sxyz<\/tt><a name=\"3fc8c994-4f4b-4741-ac68-fa11ed0736eb\"><\/a><\/h4><pre class=\"codeinput\">    Sxyz = S_xyz(0.75);\r\n    apply(Cube,Sxyz)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_07.png\" alt=\"\"> <h4>All together<a name=\"8210ccf3-d9e8-49d4-8a66-7b616ec84ceb\"><\/a><\/h4><pre class=\"codeinput\">    M = Sxyz*Tx*Ry*Rz*Rx;\r\n    apply(Cube,M)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_08.png\" alt=\"\"> <pre class=\"codeinput\">    M = Rx*Rz*Ry*Tx*Sxyz;\r\n    apply(Cube,M)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_09.png\" alt=\"\"> <h4>Clipped<a name=\"6e107ea8-f305-449a-acf8-361164c3638e\"><\/a><\/h4><p>Finally, a scrambled order.  The cube is clipped by the plot box and we see though the interior to the opposite faces.  All six colors are visible.<\/p><pre class=\"codeinput\">    M = Rz*Ry*Sxyz*Tx*Rx;\r\n    apply(Cube,M)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_10.png\" alt=\"\"> <h4>Which?<a name=\"d6b980b4-ef62-4483-a9bb-3eb045f04471\"><\/a><\/h4><p>Which do you prefer, the teapot or this cube? Leave a comment.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_670e22952baa4b5399c9d59838832563() {\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='670e22952baa4b5399c9d59838832563 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 670e22952baa4b5399c9d59838832563';\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 2021 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_670e22952baa4b5399c9d59838832563()\"><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; R2021b<br><\/p><\/div><!--\r\n670e22952baa4b5399c9d59838832563 ##### SOURCE BEGIN #####\r\n%% The Computer Graphics Matrix and a Cube\r\n% Use a cube instead of the Utah Teapot in\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2021\/10\/03\/the-matrix-at-the-heart-of-computer-graphics\r\n% my previous post>.  I was pleasantly suprised by the final screen shot.\r\n\r\n%% RGB cube\r\n% Three faces of our cube are colored with red, green and blue.\r\n% The opposite faces have the complentary colors, cyan, magenta\r\n% and yellow.  Initially, only the yellow face is visible.\r\n\r\n    Cube = grafix('6','rgb');   % Platonic solid with 6 faces.\r\n\r\n%% |Rz|\r\n    Rz = R_z(45);\r\n    apply(Cube,Rz)\r\n    \r\n%% |Rx*Rz|\r\n    Rx = R_x(60);\r\n    M = Rx*Rz;\r\n    apply(Cube,M)\r\n\r\n%% |Rz*Rx|\r\n    M = Rz*Rx;\r\n    apply(Cube,M)\r\n\r\n%% |Ry|\r\n    Ry = R_y(-120);\r\n    apply(Cube,Ry)\r\n\r\n%% |Tx|\r\n    Tx = T_x(2.5);\r\n    apply(Cube,Tx)\r\n\r\n%% |Sxyz|\r\n    Sxyz = S_xyz(0.75);\r\n    apply(Cube,Sxyz)\r\n    \r\n%% All together\r\n\r\n    M = Sxyz*Tx*Ry*Rz*Rx;\r\n    apply(Cube,M)\r\n    \r\n%%\r\n\r\n    M = Rx*Rz*Ry*Tx*Sxyz;\r\n    apply(Cube,M)\r\n\r\n\r\n%% Clipped\r\n% Finally, a scrambled order.  The cube is clipped by the plot box and\r\n% we see though the interior to the opposite faces.  All six colors\r\n% are visible.\r\n\r\n    M = Rz*Ry*Sxyz*Tx*Rx;\r\n    apply(Cube,M)\r\n    \r\n%% Which?\r\n% Which do you prefer, the teapot or this cube?\r\n% Leave a comment.\r\n##### SOURCE END ##### 670e22952baa4b5399c9d59838832563\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/grafix_cube_2_01.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>Use a cube instead of the Utah Teapot in <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2021\/10\/03\/the-matrix-at-the-heart-of-computer-graphics\">my previous post<\/a>.  I was pleasantly suprised by the final screen shot.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2021\/10\/03\/the-computer-graphics-matrix-and-a-cube\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,5,23,6],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/7488"}],"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=7488"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/7488\/revisions"}],"predecessor-version":[{"id":7566,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/7488\/revisions\/7566"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=7488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=7488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=7488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}