{"id":9867,"date":"2023-03-03T14:50:25","date_gmt":"2023-03-03T19:50:25","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=9867"},"modified":"2023-03-05T08:50:00","modified_gmt":"2023-03-05T13:50:00","slug":"r2-d2-rotations-and-dilations-in-two-dimensions","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2023\/03\/03\/r2-d2-rotations-and-dilations-in-two-dimensions\/","title":{"rendered":"R2-D2, Rotations and Dilations in Two Dimensions"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p><tt>R2_D2<\/tt> is is the name I've given a new MATLAB program that provides animations of 2-by-2 rotation and dilation matrices. I admit I chose \"dilations\" so the acronym would be memorable, but otherwise the code has little to do with the famous Star Wars droid.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#ae957d06-8d23-4754-a8c8-62af1f9bf088\">House<\/a><\/li><li><a href=\"#a3d1ea03-795d-4710-8db7-31c001648228\">Hand<\/a><\/li><li><a href=\"#c9a91f1f-8bbd-4ed9-98fa-ee0e8fb61bf7\">Rotation<\/a><\/li><li><a href=\"#e9f44bb7-087e-4cbb-997d-4164999e3127\">Dilation<\/a><\/li><li><a href=\"#fd7e7747-a58b-45b5-98c3-74e7225be987\">Both<\/a><\/li><li><a href=\"#73c4a373-5764-4623-a764-f9ca14fc29fc\"><tt>R2_D2<\/tt><\/a><\/li><li><a href=\"#c41d699a-dc5b-4fd5-92d6-a33f4dd15f85\">Further Reading<\/a><\/li><\/ul><\/div><h4>House<a name=\"ae957d06-8d23-4754-a8c8-62af1f9bf088\"><\/a><\/h4><p>This outline of a house is featured in <a href=\"https:\/\/www.mathworks.com\/moler\/exm\/chapters.html\"><i>Experiments with MATLAB<\/i><\/a>. The data are the 11 blue dots.  The coordinates of each dot form a 2-by-1 vector; the 2-by-2 rotation and dilation matrices multiply each of these vectors separately. (The lines between the dots complete the picture and are not involved in any computation.)<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/house.gif\" alt=\"\"> <\/p><p>The house also appears in several editions of Gil Strang's textbooks. The cover of the third edition of Strang's <a href=\"https:\/\/www.amazon.com\/Introduction-Linear-Algebra-Gilbert-Strang\/dp\/0961408898\"><i>Introduction to Linear Algebra<\/i><\/a> features nine houses on a quilt made by Gil's friend Chris Curtis.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/quilt.png\" alt=\"\"> <\/p><h4>Hand<a name=\"a3d1ea03-795d-4710-8db7-31c001648228\"><\/a><\/h4><p>This outline of a hand, which I made from measurements of my own hand, is also used in <a href=\"https:\/\/www.mathworks.com\/moler\/exm\/chapters.html\"><i>Experiments with MATLAB<\/i><\/a>. There are 37 points, so <tt>Hand<\/tt> is a 2-by-37 matrix.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/hand.gif\" alt=\"\"> <\/p><h4>Rotation<a name=\"c9a91f1f-8bbd-4ed9-98fa-ee0e8fb61bf7\"><\/a><\/h4><p>Multiplication by this matrix produces a two-dimensional rotation by an angle <tt>theta<\/tt>.<\/p><p>$$ R = \\left(\r\n  \\begin{array}{rr}\r\n     \\cos{\\theta} &amp; -\\sin{\\theta} \\\\\r\n     \\sin{\\theta} &amp; \\cos{\\theta}\r\n  \\end{array}\r\n  \\right) $$<\/p><p><tt>R<\/tt> is displayed in the first panel. If the house is not rotating in your browser, try this link: <a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/house_rotate.gif\">https:\/\/blogs.mathworks.com\/cleve\/files\/house_rotate.gif<\/a><\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/house_rotate.gif\" alt=\"\"> <\/p><h4>Dilation<a name=\"e9f44bb7-087e-4cbb-997d-4164999e3127\"><\/a><\/h4><p>Dilation is the process of making objects larger or smaller. Multiplication by this diagonal matrix produces a dilation by a factor <tt>sigma<\/tt>.<\/p><p>$$ S = \\left(\r\n  \\begin{array}{rr}\r\n     \\sigma &amp; 0 \\\\\r\n     0 &amp; \\sigma\r\n  \\end{array}\r\n  \\right) $$<\/p><p><tt>S<\/tt> is displayed in the second panel. The animation is also available at: <a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/hand_dilate.gif\">https:\/\/blogs.mathworks.com\/cleve\/files\/hand_dilate.gif<\/a><\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/hand_dilate.gif\" alt=\"\"> <\/p><h4>Both<a name=\"fd7e7747-a58b-45b5-98c3-74e7225be987\"><\/a><\/h4><p>Here rotation and dilation are combined. The product of the rotation and dilation matrices drives the action. If you are missing all the action, try: <a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/hand_both.gif\">https:\/\/blogs.mathworks.com\/cleve\/files\/hand_both.gif<\/a><\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/hand_both.gif\" alt=\"\"> <\/p><h4><tt>R2_D2<\/tt><a name=\"73c4a373-5764-4623-a764-f9ca14fc29fc\"><\/a><\/h4><p>When you run <tt>R2_D2<\/tt> on your own computer, you can drive the rotations and dilations yourself.  Mousing outside of the object creates rotation and mousing inside produces dilation.<\/p><p>The <tt>R2_D2<\/tt> program is available from <a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/R2_D2_14.m\">https:\/\/blogs.mathworks.com\/cleve\/files\/R2_D2_14.m<\/a><\/p><h4>Further Reading<a name=\"c41d699a-dc5b-4fd5-92d6-a33f4dd15f85\"><\/a><\/h4><p>If you are not familiar with matrices, or just want a quick refresher, check out the <a href=\"https:\/\/www.mathworks.com\/content\/dam\/mathworks\/mathworks-dot-com\/moler\/exm\/chapters\/matrices.pdf\">Matrices<\/a> chapter of <a href=\"https:\/\/www.mathworks.com\/moler\/exm\/chapters.html\"><i>Experiments with MATLAB<\/i><\/a>. Exercise 4.14 is particularly handy.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_ac09e284b90442579e910da4e5c0bd71() {\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='ac09e284b90442579e910da4e5c0bd71 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' ac09e284b90442579e910da4e5c0bd71';\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 2023 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_ac09e284b90442579e910da4e5c0bd71()\"><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; R2023a<br><\/p><\/div><!--\r\nac09e284b90442579e910da4e5c0bd71 ##### SOURCE BEGIN #####\r\n%% R2-D2, Rotations and Dilations in Two Dimensions\r\n% |R2_D2| is is the name I've given a new MATLAB program that provides\r\n% animations of 2-by-2 rotation and dilation matrices.\r\n% I admit I chose \"dilations\"\r\n% so the acronym would be memorable, but otherwise\r\n% the code has little to do with the famous Star Wars droid.\r\n\r\n%% House\r\n% This outline of a house is featured in\r\n% <https:\/\/www.mathworks.com\/moler\/exm\/chapters.html\r\n% _Experiments with MATLAB_>.\r\n% The data are the 11 blue dots.  The coordinates of each dot form a 2-by-1\r\n% vector; the 2-by-2 rotation and dilation matrices multiply each of\r\n% these vectors separately. (The lines between the dots complete the\r\n% picture and are not involved in any computation.)\r\n%\r\n% <<house.gif>>\r\n%\r\n% The house also appears in several editions of Gil Strang's textbooks.\r\n% The cover of the third edition of Strang's\r\n% <https:\/\/www.amazon.com\/Introduction-Linear-Algebra-Gilbert-Strang\/dp\/0961408898\r\n% _Introduction to Linear Algebra_> features nine houses on a quilt \r\n% made by Gil's friend Chris Curtis.\r\n%\r\n% <<quilt.png>>\r\n%\r\n\r\n\r\n%% Hand\r\n% This outline of a hand, which I made from measurements of my own hand,\r\n% is also used in \r\n% <https:\/\/www.mathworks.com\/moler\/exm\/chapters.html\r\n% _Experiments with MATLAB_>.\r\n% There are 37 points, so |Hand| is a 2-by-37 matrix.\r\n% \r\n% <<hand.gif>>\r\n%\r\n\r\n%% Rotation\r\n% Multiplication by this matrix produces a two-dimensional\r\n% rotation by an angle |theta|.  \r\n%\r\n% $$ R = \\left(\r\n%   \\begin{array}{rr}\r\n%      \\cos{\\theta} & -\\sin{\\theta} \\\\\r\n%      \\sin{\\theta} & \\cos{\\theta}\r\n%   \\end{array}\r\n%   \\right) $$\r\n%\r\n% |R| is displayed in the first panel.\r\n% If the house is not rotating in your browser, try this link:\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/house_rotate.gif>\r\n%\r\n%\r\n% <<house_rotate.gif>>\r\n%\r\n\r\n%% Dilation\r\n% Dilation is the process of making objects larger or smaller.\r\n% Multiplication by this diagonal matrix\r\n% produces a dilation by a factor |sigma|.\r\n%\r\n% $$ S = \\left(\r\n%   \\begin{array}{rr}\r\n%      \\sigma & 0 \\\\\r\n%      0 & \\sigma\r\n%   \\end{array}\r\n%   \\right) $$\r\n%\r\n% |S| is displayed in the second panel.\r\n% The animation is also available at:\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/hand_dilate.gif>\r\n%\r\n%\r\n% <<hand_dilate.gif>>\r\n%\r\n\r\n%% Both\r\n% Here rotation and dilation are combined.\r\n% The product of the rotation and dilation matrices drives the action.\r\n% If you are missing all the action, try:\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/hand_both.gif>\r\n%\r\n% <<hand_both.gif>>\r\n%\r\n\r\n%% |R2_D2|\r\n% When you run |R2_D2| on your own computer, you can drive the\r\n% rotations and dilations yourself.  Mousing outside of the object\r\n% creates rotation and mousing inside produces dilation.\r\n%\r\n% The |R2_D2| program is available from\r\n% <https:\/\/blogs.mathworks.com\/cleve\/files\/R2_D2_14.m>\r\n%\r\n%% Further Reading\r\n% If you are not familiar with matrices, or just want a quick\r\n% refresher, check out the \r\n% <https:\/\/www.mathworks.com\/content\/dam\/mathworks\/mathworks-dot-com\/moler\/exm\/chapters\/matrices.pdf\r\n% Matrices> chapter of\r\n% <https:\/\/www.mathworks.com\/moler\/exm\/chapters.html\r\n% _Experiments with MATLAB_>. \r\n% Exercise 4.14 is particularly handy.\r\n##### SOURCE END ##### ac09e284b90442579e910da4e5c0bd71\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/house.preview.gif\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction--><p><tt>R2_D2<\/tt> is is the name I've given a new MATLAB program that provides animations of 2-by-2 rotation and dilation matrices. I admit I chose \"dilations\" so the acronym would be memorable, but otherwise the code has little to do with the famous Star Wars droid.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2023\/03\/03\/r2-d2-rotations-and-dilations-in-two-dimensions\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":9876,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,23,6],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/9867"}],"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=9867"}],"version-history":[{"count":15,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/9867\/revisions"}],"predecessor-version":[{"id":9879,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/9867\/revisions\/9879"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/9876"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=9867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=9867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=9867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}