{"id":158,"date":"2008-10-31T10:23:58","date_gmt":"2008-10-31T15:23:58","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/2008\/10\/31\/olympic-rings\/"},"modified":"2008-10-31T10:24:45","modified_gmt":"2008-10-31T15:24:45","slug":"olympic-rings","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2008\/10\/31\/olympic-rings\/","title":{"rendered":"Olympic Rings"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Well, I am very late on this challenge. In August, Mike <a href=\"https:\/\/blogs.mathworks.com\/community\/2008\/08\/11\/olympic-fever\/\">posted<\/a> some code to reproduce the Olympic rings and mentioned that I might have a more clever way to create the same plot.  Here's\r\n         my attempt.\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Create X and Y Values for the 5 Rings<\/a><\/li>\r\n         <li><a href=\"#2\">Mike's Rings<\/a><\/li>\r\n         <li><a href=\"#3\">My Solution<\/a><\/li>\r\n         <li><a href=\"#8\">Loren's Rings<\/a><\/li>\r\n         <li><a href=\"#9\">Any Other Methods?<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Create X and Y Values for the 5 Rings<a name=\"1\"><\/a><\/h3>\r\n   <p>First, I'll follow Mike's parameters and code to create the initial five rings.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">N = 1000;\r\nangle = linspace(pi\/4,9*pi\/4,N);\r\n\r\nxb = cos(angle) * 0.9;\r\nyb = sin(angle) * 0.9;\r\n\r\nxy = cos(angle) * 0.9 + 1;\r\nyy = sin(angle) * 0.9 - 1;\r\n\r\nxk = cos(angle) * 0.9 + 2;\r\nyk = sin(angle) * 0.9;\r\n\r\nxg = cos(angle) * 0.9 + 3;\r\nyg = sin(angle) * 0.9 - 1;\r\n\r\nxr = cos(angle) * 0.9 + 4;\r\nyr = sin(angle) * 0.9;<\/pre><h3>Mike's Rings<a name=\"2\"><\/a><\/h3>\r\n   <p>What Mike does next is to break rings into segments for plotting so the last ring plotted in any given location is the color\r\n      that should be on top.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">h1 = figure;\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot(xb(1:3*N\/4),yb(1:3*N\/4),<span style=\"color: #A020F0\">'b'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\nplot(xy(N\/4:N),yy(N\/4:N),<span style=\"color: #A020F0\">'y'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5)\r\n\r\nplot(xk(1:3*N\/4),yk(1:3*N\/4),<span style=\"color: #A020F0\">'k'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\nplot(xy(1:N\/4),yy(1:N\/4),<span style=\"color: #A020F0\">'y'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\nplot(xb(3*N\/4:end),yb(3*N\/4:end),<span style=\"color: #A020F0\">'b'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\n\r\nplot(xr(1:N\/2),yr(1:N\/2),<span style=\"color: #A020F0\">'r'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\nplot(xg(1:N),yg(1:N),<span style=\"color: #A020F0\">'g'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\n\r\nplot(xk(3*N\/4:N),yk(3*N\/4:N),<span style=\"color: #A020F0\">'k'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\nplot(xr(N\/2:N),yr(N\/2:N),<span style=\"color: #A020F0\">'r'<\/span>,<span style=\"color: #A020F0\">'linewidth'<\/span>,5);\r\n\r\n<span style=\"color: #228B22\">% make the axis pretty<\/span>\r\naxis <span style=\"color: #A020F0\">equal<\/span>\r\naxis <span style=\"color: #A020F0\">off<\/span>\r\nxlim([-1.2 5.2])\r\nset(h1,<span style=\"color: #A020F0\">'Color'<\/span>,[1 1 1])\r\nhold <span style=\"color: #A020F0\">off<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/158\/orings_01.png\"> <h3>My Solution<a name=\"3\"><\/a><\/h3>\r\n   <p>My \"cleverness\" is to offset the rings in the Z-plane.<\/p>\r\n   <p>First I noticed that all the top rings have an axis about which I can \"tilt\" them ever so slightly to get the <b>most<\/b> of the over\/under behavior for the rings. Add small Z values to each ring.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">thetab = -pi\/4;\r\nthetak = -pi\/4;\r\nthetar = -pi\/4;<\/pre><p>Now I create Z values for the rings in the upper rows by tilting them about the axes defined by the angles above (which happen\r\n      to be identical).\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">zb = cos(angle + thetab) * 0.1;\r\nzk = cos(angle + thetak) * 0.1;\r\nzr = cos(angle + thetar) * 0.1;<\/pre><p>Next I deal with the lower rings in a lazy way, introducing a discontinuity in Z.  If I had more patience today, I could have\r\n      come up with an undulation in Z that was more than a tilted plane or a step.\r\n   <\/p>\r\n   <p>I find the angles where I need to depress the bottom rings relative to the top and set appropriate Z values for these to be\r\n      less than 0.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">mask = angle &gt;= 2*pi;\r\nzg = zeros(size(xb));\r\nzy = zeros(size(xb));\r\nzg(mask) = -0.1;\r\nzy(mask) = -0.1;<\/pre><h3>Loren's Rings<a name=\"8\"><\/a><\/h3>\r\n   <p>Here's my rendition of the rings.  My plot commands are a bit less complicated than Mike's.  I do the work earlier by setting\r\n      Z values. Also, because of my laziness, if you were to rotate my version of rings in 3-D, you'd see the bottom two aren't\r\n      really rings, but have discontinuities.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">h2 = figure;\r\nhold <span style=\"color: #A020F0\">on<\/span>\r\nplot3(xb,yb,zb,<span style=\"color: #A020F0\">'b.'<\/span>,<span style=\"color: #A020F0\">'markersize'<\/span>,10);\r\nplot3(xy,yy,zy,<span style=\"color: #A020F0\">'y.'<\/span>,<span style=\"color: #A020F0\">'markersize'<\/span>,10);\r\nplot3(xk,yk,zk,<span style=\"color: #A020F0\">'k.'<\/span>,<span style=\"color: #A020F0\">'markersize'<\/span>,10);\r\nplot3(xg,yg,zg,<span style=\"color: #A020F0\">'g.'<\/span>,<span style=\"color: #A020F0\">'markersize'<\/span>,10);\r\nplot3(xr,yr,zr,<span style=\"color: #A020F0\">'r.'<\/span>,<span style=\"color: #A020F0\">'markersize'<\/span>,10);\r\n<span style=\"color: #228B22\">% make the axis pretty<\/span>\r\naxis <span style=\"color: #A020F0\">equal<\/span>\r\naxis <span style=\"color: #A020F0\">off<\/span>\r\nxlim([-1.2 5.2])\r\nset(h2,<span style=\"color: #A020F0\">'Color'<\/span>,[1 1 1])\r\nhold <span style=\"color: #A020F0\">off<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/158\/orings_02.png\"> <h3>Any Other Methods?<a name=\"9\"><\/a><\/h3>\r\n   <p>Mike and I show 2 methods to generate interlocking rings.  Do you have any other ideas for doing this?  Let me know <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=158\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_45da401b90564a77b7a33130de7315fe() {\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='45da401b90564a77b7a33130de7315fe ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 45da401b90564a77b7a33130de7315fe';\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        author = 'Loren Shure';\r\n        copyright = 'Copyright 2008 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 author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\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      \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_45da401b90564a77b7a33130de7315fe()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.7<br><\/p>\r\n<\/div>\r\n<!--\r\n45da401b90564a77b7a33130de7315fe ##### SOURCE BEGIN #####\r\n%% Olympic Rings\r\n% Well, I am very late on this challenge. In August, Mike \r\n% <https:\/\/blogs.mathworks.com\/community\/2008\/08\/11\/olympic-fever\/ posted>\r\n% some code to reproduce the Olympic rings and mentioned that I might have\r\n% a more clever way to create the same plot.  Here's my attempt.\r\n\r\n%% Create X and Y Values for the 5 Rings\r\n% First, I'll follow Mike's parameters and code to create the initial five\r\n% rings.\r\nN = 1000;\r\nangle = linspace(pi\/4,9*pi\/4,N); \r\n\r\nxb = cos(angle) * 0.9;\r\nyb = sin(angle) * 0.9;\r\n\r\nxy = cos(angle) * 0.9 + 1;\r\nyy = sin(angle) * 0.9 - 1;\r\n\r\nxk = cos(angle) * 0.9 + 2;\r\nyk = sin(angle) * 0.9;\r\n\r\nxg = cos(angle) * 0.9 + 3;\r\nyg = sin(angle) * 0.9 - 1;\r\n\r\nxr = cos(angle) * 0.9 + 4;\r\nyr = sin(angle) * 0.9;\r\n\r\n\r\n%% Mike's Rings\r\n% What Mike does next is to break rings into segments for plotting so the\r\n% last ring plotted in any given location is the color that should be on\r\n% top.\r\nh1 = figure;\r\nhold on\r\nplot(xb(1:3*N\/4),yb(1:3*N\/4),'b','linewidth',5);\r\nplot(xy(N\/4:N),yy(N\/4:N),'y','linewidth',5)\r\n\r\nplot(xk(1:3*N\/4),yk(1:3*N\/4),'k','linewidth',5);\r\nplot(xy(1:N\/4),yy(1:N\/4),'y','linewidth',5);\r\nplot(xb(3*N\/4:end),yb(3*N\/4:end),'b','linewidth',5);\r\n\r\nplot(xr(1:N\/2),yr(1:N\/2),'r','linewidth',5);\r\nplot(xg(1:N),yg(1:N),'g','linewidth',5);\r\n\r\nplot(xk(3*N\/4:N),yk(3*N\/4:N),'k','linewidth',5);\r\nplot(xr(N\/2:N),yr(N\/2:N),'r','linewidth',5);\r\n\r\n% make the axis pretty\r\naxis equal\r\naxis off\r\nxlim([-1.2 5.2])\r\nset(h1,'Color',[1 1 1])\r\nhold off\r\n\r\n%% My Solution\r\n% My \"cleverness\" is to offset the rings in the Z-plane.  \r\n%%\r\n% First I noticed that all the top rings have an axis about which I can\r\n% \"tilt\" them ever so slightly to get the *most* of the over\/under behavior\r\n% for the rings. Add small Z values to each ring.\r\nthetab = -pi\/4;\r\nthetak = -pi\/4;\r\nthetar = -pi\/4;\r\n\r\n%% \r\n% Now I create Z values for the rings in the upper rows by tilting them\r\n% about the axes defined by the angles above (which happen to be\r\n% identical).\r\nzb = cos(angle + thetab) * 0.1;\r\nzk = cos(angle + thetak) * 0.1;\r\nzr = cos(angle + thetar) * 0.1;\r\n\r\n%% \r\n% Next I deal with the lower rings in a lazy way, introducing a\r\n% discontinuity in Z.  If I had more patience today, I could have come up\r\n% with an undulation in Z that was more than a tilted plane or a step.\r\n%%\r\n% I find the angles where I need to depress the bottom rings relative to\r\n% the top and set appropriate Z values for these to be less than 0.\r\nmask = angle >= 2*pi;\r\nzg = zeros(size(xb));\r\nzy = zeros(size(xb));\r\nzg(mask) = -0.1;\r\nzy(mask) = -0.1;\r\n\r\n%% Loren's Rings\r\n% Here's my rendition of the rings.  My plot commands are a bit less\r\n% complicated than Mike's.  I do the work earlier by setting Z values.\r\n% Also, because of my laziness, if you were to rotate my version of rings\r\n% in 3-D, you'd see the bottom two aren't really rings, but have\r\n% discontinuities.\r\nh2 = figure;\r\nhold on\r\nplot3(xb,yb,zb,'b.','markersize',10);\r\nplot3(xy,yy,zy,'y.','markersize',10);\r\nplot3(xk,yk,zk,'k.','markersize',10);\r\nplot3(xg,yg,zg,'g.','markersize',10);\r\nplot3(xr,yr,zr,'r.','markersize',10);\r\n% make the axis pretty\r\naxis equal\r\naxis off\r\nxlim([-1.2 5.2])\r\nset(h2,'Color',[1 1 1])\r\nhold off\r\n%% Any Other Methods?\r\n% Mike and I show 2 methods to generate interlocking rings.  Do you have\r\n% any other ideas for doing this?  Let me know\r\n% <https:\/\/blogs.mathworks.com\/loren\/?p=158 here>.\r\n##### SOURCE END ##### 45da401b90564a77b7a33130de7315fe\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Well, I am very late on this challenge. In August, Mike posted some code to reproduce the Olympic rings and mentioned that I might have a more clever way to create the same plot. ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2008\/10\/31\/olympic-rings\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/158"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}