{"id":7185,"date":"2020-05-14T17:30:48","date_gmt":"2020-05-14T21:30:48","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=7185"},"modified":"2020-05-14T17:30:48","modified_gmt":"2020-05-14T21:30:48","slug":"circles-all-the-way-down","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2020\/05\/14\/circles-all-the-way-down\/","title":{"rendered":"Circles All the Way Down"},"content":{"rendered":"<p>This is a story about how ideas\u00a0 and code bounce around our shared social spaces. This one went from Twitter to GitHub to my computer and now to you in my blog. Social serendipity has really been amplified by all the forms of community sharing available to us these days. It&#8217;s fun to dive into it and see where you end up.<\/p>\n<p>Our story begins when <a href=\"https:\/\/twitter.com\/matthen2\">Matt Henderson<\/a> posts a <a href=\"https:\/\/twitter.com\/matthen2\/status\/1256824725814120448\">tweet with this video<\/a>. This is just one of the dozens of assorted brain-bending mathematical visualizations he has published (do yourself a favor and follow him).<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-7201\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_01.png\" alt=\"\" width=\"473\" height=\"582\" \/><\/p>\n<p>Watch the video! The idea is to use the special area=1 rectangle shown as a tracing tool to transform one set of circles into another one. The set of circles above spreads out to infinity. The other corresponding set of circles is mapped inside a circular region below the first set.<\/p>\n<p>As a MATLAB fan, I was delighted to see my friend <a href=\"https:\/\/twitter.com\/Lazrhog\">Jason C<\/a> follow up with <a href=\"https:\/\/twitter.com\/Lazrhog\/status\/1257924815719145472\">this tweet<\/a>:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-7203\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_02.png\" alt=\"\" width=\"472\" height=\"602\" \/><\/p>\n<p>&#8220;Can I see your code?&#8221; I inquired, and he generously responded by posting it all to a <a href=\"https:\/\/github.com\/Lazrhog\/matthen2_circ\">GitHub repo<\/a>. He says he banged it out during a quick lunch break. Here is the output from Jason&#8217;s code, and sure enough it reproduces his image shown above. I love GitHub!<\/p>\n<pre id=\"matlabcode\" class=\"matlab-code\" style=\"background-color: #f7f7f7; font-family: monospace; font-weight: normal; padding-top: 5px; padding-bottom: 5px; line-height: 150%; border: 1px solid #E9E9E9;\">clf\r\n<span style=\"color: #228b22;\">% Start with a line to get outer circle<\/span>\r\nLinePlot(100,2000)\r\n<span style=\"color: #228b22;\">% Then draw a bunch of circles<\/span>\r\n<span style=\"color: #0000ff;\">for<\/span> a=-50.5:50.5\r\n<span style=\"color: #0000ff;\">  for<\/span> b=1.5:10.5\r\n    CirclePlot(100,0.5,[a b])\r\n<span style=\"color: #0000ff;\">  end<\/span>\r\n<span style=\"color: #0000ff;\">end<\/span>\r\naxis <span style=\"color: #a020f0;\">equal<\/span>\r\naxis <span style=\"color: #a020f0;\">off<\/span>\r\n<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"560\" height=\"420\" class=\"alignnone size-full wp-image-7205\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_03.png\" alt=\"\" \/><\/p>\n<p>I was looking at the original transform and thinking about how it was kind of a sideways inversion (and Matthew <a href=\"https:\/\/twitter.com\/matthen2\/status\/1256825042995834883\">makes this observation himself<\/a>). I knew that if I could map it to MATLAB&#8217;s native complex math functionality, the code to plot this could get really small.<\/p>\n<p>Here&#8217;s the diagram I drew. The tracing point is z1 and the drawing point is z2.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"651\" height=\"319\" class=\"alignnone size-full wp-image-7207\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_04.png\" alt=\"\" \/><\/p>\n<p>By inspection, we can construct z2 by rotating z1 counterclockwise 90 degrees (multiplying it by i) and then scaling it using the assumption that the area of the rectangle is 1.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"141\" height=\"41\" class=\"alignnone size-full wp-image-7195\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_eq01.png\" alt=\"\" \/><\/p>\n<p>So<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"227\" height=\"42\" class=\"alignnone size-full wp-image-7197\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_eq02.png\" alt=\"\" \/><\/p>\n<p>But hey! I happen to know that<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"149\" height=\"42\" class=\"alignnone size-full wp-image-7199\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_eq03.png\" alt=\"\" \/><\/p>\n<p>Check it out! You can now see that real(z2) = imag(1\/z1), and imag(z2) = real(1\/z1). Now we&#8217;re ready to fly. Fasten your seatbelts!<\/p>\n<p>We&#8217;re going to overlay these new circles in blue on top of Jason&#8217;s plot.<\/p>\n<pre id=\"matlabcode\" class=\"matlab-code\" style=\"background-color: #f7f7f7; font-family: monospace; font-weight: normal; padding-top: 5px; padding-bottom: 5px; line-height: 150%; border: 1px solid #E9E9E9;\"><span style=\"color: #228b22;\">% Set the centers of the circles<\/span>\r\n[x,y] = meshgrid(-50.5:50.5,1.5:10.5);\r\n<span style=\"color: #228b22;\">% Make a template circle to apply inside the loop<\/span>\r\nt = linspace(0,2*pi,100);\r\nct = 0.5*cos(t);\r\nst = 0.5*sin(t);\r\n<span style=\"color: #228b22;\">% Loop through all the center points<\/span>\r\n<span style=\"color: #0000ff;\">for<\/span> i = 1:numel(x)\r\n\r\n<span style=\"color: #228b22;\">  % Build one circle <\/span>\r\n  xc = x(i)+ct;\r\n  yc = y(i)+st;\r\n\r\n<span style=\"color: #228b22;\">  % ... and invert it<\/span>\r\n  z = xc + 1i*yc;\r\n  zi = 1.\/z;\r\n\r\n<span style=\"color: #228b22;\">  % Flip the real and imaginary components and plot<\/span>\r\n  line(imag(zi),real(zi))\r\n\r\n<span style=\"color: #228b22;\">  % And Bob's your uncle...<\/span>\r\n<span style=\"color: #0000ff;\">end<\/span>\r\n<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"560\" height=\"420\" class=\"alignnone size-full wp-image-7209\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_05.png\" alt=\"\" \/><\/p>\n<p>Those are the same circles! We can validate this by zooming way in.<\/p>\n<pre id=\"matlabcode\" class=\"matlab-code\" style=\"background-color: #f7f7f7; font-family: monospace; font-weight: normal; padding-top: 5px; padding-bottom: 5px; line-height: 150%; border: 1px solid #E9E9E9;\">xlim([-0.0982 -0.0452])\r\nylim([0.0301 0.0719])\r\n<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"560\" height=\"420\" class=\"alignnone size-full wp-image-7189\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_06.png\" alt=\"\" \/><\/p>\n<p>If you want a better sense of what&#8217;s happening with the transform, here is an animation with some intermediate steps. I had to use a super-fast camera to catch the MATLAB elves in the act of inverting complex numbers. You can&#8217;t generally see this with the naked eye.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"435\" height=\"368\" class=\"alignnone size-full wp-image-7191\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_07.gif\" alt=\"\" \/><\/p>\n<p>I find it fascinating that the mapping preserves circles as circles, while the squares they sit in are severely warped. Here I&#8217;ve removed the circles and just left the (inverted) grid.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"355\" height=\"359\" class=\"alignnone size-full wp-image-7193\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_08.png\" alt=\"\" \/><\/p>\n<p>This is all basic analysis, but it&#8217;s fun to take a walking tour of the complex plane and see what turns up. And it&#8217;s especially fun when you&#8217;re bouncing around ideas with friends and colleagues from all over the web. So cheers to Matthew Henderson and Jason C for the inspiration!<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/circles_01.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>This is a story about how ideas\u00a0 and code bounce around our shared social spaces. This one went from Twitter to GitHub to my computer and now to you in my blog. Social serendipity has really been&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2020\/05\/14\/circles-all-the-way-down\/\">read more >><\/a><\/p>\n","protected":false},"author":69,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/7185"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=7185"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/7185\/revisions"}],"predecessor-version":[{"id":7219,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/7185\/revisions\/7219"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=7185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=7185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=7185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}