<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Olympic Rings</title>
	<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/</link>
	<description>Loren Shure  works on design of the MATLAB language at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Sun, 22 Nov 2009 22:59:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Tom Elmer</title>
		<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29858</link>
		<dc:creator>Tom Elmer</dc:creator>
		<pubDate>Mon, 10 Nov 2008 16:54:03 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29858</guid>
		<description>&lt;i&gt;I fix Loren’s code a little bit to be able to reuse x and y and with a shorter plot command ;) &lt;/i&gt;

You missed the important part of the exercise in that the rings have to be interlocking :D</description>
		<content:encoded><![CDATA[<p><i>I fix Loren’s code a little bit to be able to reuse x and y and with a shorter plot command ;) </i></p>
<p>You missed the important part of the exercise in that the rings have to be interlocking :D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hung Dang</title>
		<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29855</link>
		<dc:creator>Hung Dang</dc:creator>
		<pubDate>Sat, 08 Nov 2008 15:20:04 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29855</guid>
		<description>I fix Loren's code a little bit to be able to reuse x and y and with a shorter plot command ;) 

%% Init parameters
R = 0.9;
scale = 1.1;
N = 100;
thickness = 10;
angle = linspace(0,2*pi,N);

%% Plot the rings
y = R * sin(angle);
x = R * cos(angle);
plot(x,y,'b',x + scale * R,y - scale * R,'k',x + 2 * scale * R,y,'r',...
    x + 3 * scale * R, y - scale * R,'g',x + 4 * scale * R,y,'k',...
    'LineWidth',thickness);

%% Make axis look better
axis off;
set(gca,'XLim',[-1.2 5.2]);
set(gcf,'Color',[1 1 1]);</description>
		<content:encoded><![CDATA[<p>I fix Loren&#8217;s code a little bit to be able to reuse x and y and with a shorter plot command ;) </p>
<p>%% Init parameters<br />
R = 0.9;<br />
scale = 1.1;<br />
N = 100;<br />
thickness = 10;<br />
angle = linspace(0,2*pi,N);</p>
<p>%% Plot the rings<br />
y = R * sin(angle);<br />
x = R * cos(angle);<br />
plot(x,y,&#8217;b',x + scale * R,y - scale * R,&#8217;k',x + 2 * scale * R,y,&#8217;r',&#8230;<br />
    x + 3 * scale * R, y - scale * R,&#8217;g',x + 4 * scale * R,y,&#8217;k',&#8230;<br />
    &#8216;LineWidth&#8217;,thickness);</p>
<p>%% Make axis look better<br />
axis off;<br />
set(gca,&#8217;XLim&#8217;,[-1.2 5.2]);<br />
set(gcf,&#8217;Color&#8217;,[1 1 1]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29851</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 06 Nov 2008 12:43:01 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29851</guid>
		<description>Tom-

Thanks for an interesting and elegant solution!

--Loren</description>
		<content:encoded><![CDATA[<p>Tom-</p>
<p>Thanks for an interesting and elegant solution!</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Elmer</title>
		<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29850</link>
		<dc:creator>Tom Elmer</dc:creator>
		<pubDate>Thu, 06 Nov 2008 01:24:12 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29850</guid>
		<description>&lt;i&gt;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 come up with an undulation in Z that was more than a tilted plane or a step. &lt;/i&gt;

No need to add undulations, just alternate your axis (and I added an alternating offset) then increment the angles/offsets on each ring.  (Of course they're really ellipses in 3D but the 2D projection is circular. Actually, it looks kinda neat on Y-Z view.)  (I wasn't mathematically rigorous on what the coefficients should be for N rings, but I did try it out to 28 rings.) 

N = 1000;                       
angle = linspace(pi/4,9*pi/4,N);
                                
c='bykgr';
%c='bykgrmcbykgrmcbykgrmcbykgrmc';
index = 1:length(c);
UL=( ~mod(index,2) - mod(index,2) ); %negative if Upper ring, positive if Lower ring

h2 = figure('color',[1 1 1]);
hold on
for loop=1:length(c)
  z = cos(angle + UL(loop)*pi/4) * ... %alternating axes
    (length(c)-loop)*0.1*-UL(loop) + ... %alternating angles
    .05*(length(c)-loop)*-UL(loop); %alternating depth offsets
  x = cos(angle) * 0.9 + (loop-1);
  y = sin(angle) * 0.9 - ~mod(loop,2);
  plot3(x,y,z,[c(loop) '.'],'markersize',10);
end
axis equal off
hold off</description>
		<content:encoded><![CDATA[<p><i>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 come up with an undulation in Z that was more than a tilted plane or a step. </i></p>
<p>No need to add undulations, just alternate your axis (and I added an alternating offset) then increment the angles/offsets on each ring.  (Of course they&#8217;re really ellipses in 3D but the 2D projection is circular. Actually, it looks kinda neat on Y-Z view.)  (I wasn&#8217;t mathematically rigorous on what the coefficients should be for N rings, but I did try it out to 28 rings.) </p>
<p>N = 1000;<br />
angle = linspace(pi/4,9*pi/4,N);</p>
<p>c=&#8217;bykgr&#8217;;<br />
%c=&#8217;bykgrmcbykgrmcbykgrmcbykgrmc&#8217;;<br />
index = 1:length(c);<br />
UL=( ~mod(index,2) - mod(index,2) ); %negative if Upper ring, positive if Lower ring</p>
<p>h2 = figure(&#8217;color&#8217;,[1 1 1]);<br />
hold on<br />
for loop=1:length(c)<br />
  z = cos(angle + UL(loop)*pi/4) * &#8230; %alternating axes<br />
    (length(c)-loop)*0.1*-UL(loop) + &#8230; %alternating angles<br />
    .05*(length(c)-loop)*-UL(loop); %alternating depth offsets<br />
  x = cos(angle) * 0.9 + (loop-1);<br />
  y = sin(angle) * 0.9 - ~mod(loop,2);<br />
  plot3(x,y,z,[c(loop) &#8216;.&#8217;],&#8217;markersize&#8217;,10);<br />
end<br />
axis equal off<br />
hold off</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29843</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 05 Nov 2008 12:21:37 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29843</guid>
		<description>Mark-

Thanks so much for sharing an entirely different approach!

--Loren</description>
		<content:encoded><![CDATA[<p>Mark-</p>
<p>Thanks so much for sharing an entirely different approach!</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mark</title>
		<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29842</link>
		<dc:creator>mark</dc:creator>
		<pubDate>Tue, 04 Nov 2008 21:47:17 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29842</guid>
		<description>If you want to do it as an image versus a plot then you can utilize convolution since the rings are identical.  Admittedly the output doesn't look as nice as above but I think it is a nice demonstration of the conv2 function...maybe.  

% first create a 'ring' 

x=sin(2*pi*(1/100)*(0:99));
y=cos(2*pi*(1/100)*(0:99)); 
c=zeros(32,32); 
for i=1:100
    c(ceil(15*x(i))+16,ceil(15*y(i))+16)=1;
end 


% then create your canvas
A=zeros(128,128);

% set ring spacing
n=36; 

% convolving this set of impulses with 
% the ring will make the final output array
% the different values will change the colors
A(64,((0:2)*n)+20)=[1 3 5];
A(64+15,([1/2 3/2]*n)+20)=[2 4]; 

% use this to test the overlaps
D(64,((0:2)*n)+20)=[1 1 1];
D(64+15,([1/2 3/2]*n)+20)=[1 1]; 


w=conv2(D,c,'same');

% find where the rings overlap
[s,t]=find(w==2);


f=[2 2 1 2 3 4 4 3 4 5];

% create the final output array
r=conv2(A,c,'same'); 

% replace with the 'right values from left to right
for ii=1:10
    r(s(ii),t(ii))=f(ii); 
end

% set the color map to a white background 
% and five colors
map=[1 1 1 ; 0 0 1 ; 1 1 0 ; 0 0 0 ; 0 1 0 ; 1 0 0]

% display
imagesc(r)

colormap(map);</description>
		<content:encoded><![CDATA[<p>If you want to do it as an image versus a plot then you can utilize convolution since the rings are identical.  Admittedly the output doesn&#8217;t look as nice as above but I think it is a nice demonstration of the conv2 function&#8230;maybe.  </p>
<p>% first create a &#8216;ring&#8217; </p>
<p>x=sin(2*pi*(1/100)*(0:99));<br />
y=cos(2*pi*(1/100)*(0:99));<br />
c=zeros(32,32);<br />
for i=1:100<br />
    c(ceil(15*x(i))+16,ceil(15*y(i))+16)=1;<br />
end </p>
<p>% then create your canvas<br />
A=zeros(128,128);</p>
<p>% set ring spacing<br />
n=36; </p>
<p>% convolving this set of impulses with<br />
% the ring will make the final output array<br />
% the different values will change the colors<br />
A(64,((0:2)*n)+20)=[1 3 5];<br />
A(64+15,([1/2 3/2]*n)+20)=[2 4]; </p>
<p>% use this to test the overlaps<br />
D(64,((0:2)*n)+20)=[1 1 1];<br />
D(64+15,([1/2 3/2]*n)+20)=[1 1]; </p>
<p>w=conv2(D,c,&#8217;same&#8217;);</p>
<p>% find where the rings overlap<br />
[s,t]=find(w==2);</p>
<p>f=[2 2 1 2 3 4 4 3 4 5];</p>
<p>% create the final output array<br />
r=conv2(A,c,&#8217;same&#8217;); </p>
<p>% replace with the &#8216;right values from left to right<br />
for ii=1:10<br />
    r(s(ii),t(ii))=f(ii);<br />
end</p>
<p>% set the color map to a white background<br />
% and five colors<br />
map=[1 1 1 ; 0 0 1 ; 1 1 0 ; 0 0 0 ; 0 1 0 ; 1 0 0]</p>
<p>% display<br />
imagesc(r)</p>
<p>colormap(map);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29833</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Fri, 31 Oct 2008 15:29:08 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/10/31/olympic-rings/#comment-29833</guid>
		<description>That's great. I'm so used to thinking in 2-dimensions with my plots.</description>
		<content:encoded><![CDATA[<p>That&#8217;s great. I&#8217;m so used to thinking in 2-dimensions with my plots.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
