<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807</link>
    <title>MATLAB Central Newsreader - Draw a star.</title>
    <description>Feed for thread: Draw a star.</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 20 Dec 2007 03:25:30 -0500</pubDate>
      <title>Re: Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#406820</link>
      <author>Roger Stafford</author>
      <description>"Ionut Plesa" &amp;lt;hartson9@k.ro&amp;gt; wrote in message &amp;lt;fkc8vb$7rg&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)&lt;br&gt;
&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;lt;ellieandrogerxyzzy-2008061008490001@dialup-4.232.60.187.dial1.losan&lt;br&gt;
geles1.level3.net&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; theta = 0:4/5*pi:4*pi;&lt;br&gt;
&amp;gt; &amp;gt; plot(cos(theta),sin(theta),'y-')&lt;br&gt;
&amp;gt; &amp;gt; axis equal&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Roger Stafford&lt;br&gt;
&amp;gt; How can i fill this star with colour? Make it a coloured star.&lt;br&gt;
---------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Matlab's 'fill' instruction interprets the area inside the star's inner pentagon &lt;br&gt;
as being outside the fill area, since it is inside "twice", so to speak.  Therefore &lt;br&gt;
that pentagon area doesn't get filled.  My solution would be to rewrite the &lt;br&gt;
program so that the polygon doesn't cross itself, something along the lines of &lt;br&gt;
the fourteen-pointed star method earlier in this thread.  Similarly to that &lt;br&gt;
problem, fix it so that the polygon alternates repeatedly between the r1 and &lt;br&gt;
r2 radii as theta increases from 0 to 2*pi.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;theta = 0:2/10*pi:2*pi;&lt;br&gt;
&amp;nbsp;r1 = 1; r2 = cos(2*pi/5)/cos(pi/5);&lt;br&gt;
&amp;nbsp;r = (r1+r2)/2 + (r1-r2)/2*(-1).^[0:10];&lt;br&gt;
&amp;nbsp;x = r.*cos(theta); y = r.*sin(theta);&lt;br&gt;
&amp;nbsp;fill(x,y,'y')&lt;br&gt;
&amp;nbsp;axis equal&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Wed, 19 Dec 2007 23:20:11 -0500</pubDate>
      <title>Re: Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#406807</link>
      <author>Ionut Plesa</author>
      <description>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)&lt;br&gt;
wrote in message&lt;br&gt;
&amp;lt;ellieandrogerxyzzy-2008061008490001@dialup-4.232.60.187.dial1.losangeles1.level3.net&amp;gt;...&lt;br&gt;
&amp;gt; theta = 0:4/5*pi:4*pi;&lt;br&gt;
&amp;gt; plot(cos(theta),sin(theta),'y-')&lt;br&gt;
&amp;gt; axis equal&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
How can i fill this star with colour? Make it a coloured star.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 21 Aug 2006 08:01:43 -0400</pubDate>
      <title>Re: Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#329463</link>
      <author>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)</author>
      <description>In article &amp;lt;ecbin502r8a@drn.newsguy.com&amp;gt;, Patrick Flaherty&lt;br&gt;
&amp;lt;Patrick_member@newsguy.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; .....&lt;br&gt;
&amp;gt; A further question though if I might.  I understand reasonably the&lt;br&gt;
&amp;gt; code and explanation you give.  It's my impression though that this&lt;br&gt;
&amp;gt; method is considerably different from what the professor indicated in&lt;br&gt;
&amp;gt; his hints - using 2 complex vectors; e^(i*theta),etc; and a third&lt;br&gt;
&amp;gt; complex vector to normalize the axes.&lt;br&gt;
&amp;gt; ......&lt;br&gt;
&amp;gt; pat&lt;br&gt;
-----------------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Writing v = r.*exp(i*theta)), x = real(v), y = imag(v) is equivalent to&lt;br&gt;
saying x = r.*cos(theta) and y = r.*sin(t).&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;It is possible the professor was hinting at something like the following&lt;br&gt;
to achieve the desired change of radius using two rotating vectors, one at&lt;br&gt;
the end of the other:&lt;br&gt;
&lt;br&gt;
theta = (-1/4:1/28:3/4)*2*pi; % The slow rotation&lt;br&gt;
phi = (0:28)*pi; % The rapid rotation&lt;br&gt;
v = (r1+r2)/2*exp(i*theta) + (r1-r2)/2*exp(i*(theta+phi));&lt;br&gt;
x = real(v); y = imag(v);&lt;br&gt;
&lt;br&gt;
At each step the angle theta changes by pi/14 or 1/28 of a revolution,&lt;br&gt;
while phi changes by a half a revolution, so theta+phi changes by&lt;br&gt;
1/28+1/2=15/28 of a revolution.  It is a rotation of one vector about the&lt;br&gt;
end of another longer, more slowly rotating vector.  It adds up to the&lt;br&gt;
same effect as using r = (r1+r2)/2 + (r1-r2)/2*(-1).^[0:28] which&lt;br&gt;
alternates between r1 and r2 in radius.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;I don't know what he planned for the third vector to normalize the&lt;br&gt;
axes.  I can't think of anything in matlab that would work to ensure the&lt;br&gt;
units along the two axes are of the same length except a specific&lt;br&gt;
reference to the 'axes' function or its equivalent, such as 'axes equal'.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 21 Aug 2006 03:41:00 -0400</pubDate>
      <title>Re: Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#329441</link>
      <author>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)</author>
      <description>In article &amp;lt;ecau8b0197n@drn.newsguy.com&amp;gt;, Patrick Flaherty&lt;br&gt;
&amp;lt;Patrick_member@newsguy.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; ....&lt;br&gt;
&amp;gt; However the star there is 14-pointed (not 5).&lt;br&gt;
&amp;gt; ....&lt;br&gt;
----------------------------&lt;br&gt;
&amp;nbsp;&amp;nbsp;The Malaysian fourteen-pointed star is a bit more of a challenge.&lt;br&gt;
&lt;br&gt;
% The rectanglar background&lt;br&gt;
a = 80; b = 60;&lt;br&gt;
x1 = [a,-a,-a,a,a];&lt;br&gt;
y1 = [b,b,-b,-b,b];&lt;br&gt;
&lt;br&gt;
% The star&lt;br&gt;
t = (-1/4:1/28:3/4)*2*pi;&lt;br&gt;
r1 = 44; r2 = 19;&lt;br&gt;
r = (r1+r2)/2 + (r1-r2)/2*(-1).^[0:28];&lt;br&gt;
x2 = r.*cos(t);&lt;br&gt;
y2 = r.*sin(t);&lt;br&gt;
&lt;br&gt;
% Fill the polygons&lt;br&gt;
fill(x1,y1,'b',x2,y2,'y')&lt;br&gt;
axis equal&lt;br&gt;
&lt;br&gt;
Brief description: x1 and y1 trace out a 160 by 120 rectangular polygon. &lt;br&gt;
The angle t progresses from -pi/2 to +3/2*pi in steps of 2*pi/28 for the&lt;br&gt;
28 line segments of the star, while r alternates between radius 44 and&lt;br&gt;
19.  x2 and y2 have the coordinates of the alternate outer and inner&lt;br&gt;
successive points of the polygon defining the star.  The 'fill' command&lt;br&gt;
first draws a blue rectangle and then superimposes the yellow star.  'axis&lt;br&gt;
equal' ensures that scaling is equal between the x and y axes in the plot.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;My advice to you would be, not to give your nephew the above complete&lt;br&gt;
code, but to describe in broad terms the nature of the steps involved and&lt;br&gt;
let him work out the details: how to generate polygonal points on two&lt;br&gt;
different circles using an angle t and a radius r which alternates between&lt;br&gt;
two fixed radii; then the conversion to cartesian coordinates x =&lt;br&gt;
r.*cos(t) and y = r.*sin(t); and finally how the 'fill' function is used&lt;br&gt;
to fill the interior of polygons with selected colors.  He will learn more&lt;br&gt;
if he has to do some of the work.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 20 Aug 2006 23:09:41 -0400</pubDate>
      <title>Re: Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#329454</link>
      <author>Patrick Flaherty</author>
      <description>In article&lt;br&gt;
&amp;lt;ellieandrogerxyzzy-2008062041000001@dialup-4.232.6.13.dial1.losangeles1.level3.net&amp;gt;,&lt;br&gt;
Roger Stafford says...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;In article &amp;lt;ecau8b0197n@drn.newsguy.com&amp;gt;, Patrick Flaherty&lt;br&gt;
&amp;gt;&amp;lt;Patrick_member@newsguy.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; ....&lt;br&gt;
&amp;gt;&amp;gt; However the star there is 14-pointed (not 5).&lt;br&gt;
&amp;gt;&amp;gt; ....&lt;br&gt;
&amp;gt;----------------------------&lt;br&gt;
&amp;gt;  The Malaysian fourteen-pointed star is a bit more of a challenge.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ....&lt;br&gt;
&lt;br&gt;
Much thanx Roger.  You're more than generous with both your time&lt;br&gt;
and explanation.&lt;br&gt;
&lt;br&gt;
A further question though if I might.  I understand reasonably the&lt;br&gt;
code and explanation you give.  It's my impression though that this&lt;br&gt;
method is considerably different from what the professor indicated in&lt;br&gt;
his hints - using 2 complex vectors; e^(i*theta),etc; and a third&lt;br&gt;
complex vector to normalize the axes.&lt;br&gt;
&lt;br&gt;
Briefly, as best I understand, you're sweeping out a clock-like motion,&lt;br&gt;
moving in-and-out for each node (point) and edge.  Whereas what the &lt;br&gt;
professor was suggesting (I believe) was something more like deforming&lt;br&gt;
a circle into the required star shape.&lt;br&gt;
&lt;br&gt;
Or am I incorrect?&lt;br&gt;
&lt;br&gt;
thanx.&lt;br&gt;
&lt;br&gt;
pat&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 20 Aug 2006 17:20:27 -0400</pubDate>
      <title>Re: Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#329435</link>
      <author>Patrick Flaherty</author>
      <description>thanx Roger - yes that worked perfectly.&lt;br&gt;
&lt;br&gt;
I assume the 'cos(theta),sin(theta)' bit was as in&lt;br&gt;
e^(i*theta) = cos(theta) + i*sin(theta)?&lt;br&gt;
&lt;br&gt;
And playing with the code below a bit, the 4/5s and&lt;br&gt;
the 4 (defining the theta range) are what get you&lt;br&gt;
the 5-pointed star?  Although exactly how this works,&lt;br&gt;
I'm not yet sure.  (but Matlab is a great tool for&lt;br&gt;
just playing with things [and learning them thereby]).&lt;br&gt;
&lt;br&gt;
That was the warm-up.  I'm actually trying to work on&lt;br&gt;
a homework problem for my wife's eldest brother's eldest&lt;br&gt;
son. The son is now in his first year at a technical&lt;br&gt;
university.  The program is bio-chemical engineering but&lt;br&gt;
of course he needs to learn to program and is doing&lt;br&gt;
so for the first time.&lt;br&gt;
&lt;br&gt;
I'm a programmer and so I'd been helping him out already,&lt;br&gt;
when he was first using SciLab.  Which, as best I could make&lt;br&gt;
out (and I hadn't seen SciLab before either) is maybe &lt;br&gt;
something like a student version of Matlab.&lt;br&gt;
&lt;br&gt;
He's in Malaysia (my wife's from Malaysia).&lt;br&gt;
&lt;br&gt;
The actual problem is to recreate the star that's in the upper&lt;br&gt;
left of the Malaysian flag (drawing it in Matlab of course).&lt;br&gt;
The star, that is, that's just to the right of the crescent&lt;br&gt;
moon (Muslim symbolism).&lt;br&gt;
&lt;br&gt;
However the star there is 14-pointed (not 5).  I tried switching&lt;br&gt;
the 4/5 and 4 in your code to 14/15 and 14 and I got something&lt;br&gt;
vaguely like a 14-pointed star except that there was a '15th'&lt;br&gt;
point which didn't close at its tip.  Maybe the odd and even&lt;br&gt;
(number of points) cases differ ...&lt;br&gt;
&lt;br&gt;
In accomplishing the task, the hmwk gives a small amount&lt;br&gt;
of (doubtless invaluable) information.&lt;br&gt;
&lt;br&gt;
1. start by defining two vectors of complex #s Zsub1 = r*e^(i*theta)&lt;br&gt;
and rsubZsub2 = 0.5*rsubZsub1&lt;br&gt;
&lt;br&gt;
(Thus r diminishing by 1/2 with each subsequent term.)&lt;br&gt;
&lt;br&gt;
and 2. normalize the scales with a third Zsub3 where&lt;br&gt;
Zsub3*(2n-1) = Zsub1*(n).&lt;br&gt;
&lt;br&gt;
pat&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
In article&lt;br&gt;
&amp;lt;ellieandrogerxyzzy-2008061008490001@dialup-4.232.60.187.dial1.losangeles1.level3.net&amp;gt;,&lt;br&gt;
Roger Stafford says...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;theta = 0:4/5*pi:4*pi;&lt;br&gt;
&amp;gt;plot(cos(theta),sin(theta),'y-')&lt;br&gt;
&amp;gt;axis equal&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 20 Aug 2006 17:08:49 -0400</pubDate>
      <title>Re: Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#329385</link>
      <author>ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)</author>
      <description>theta = 0:4/5*pi:4*pi;&lt;br&gt;
plot(cos(theta),sin(theta),'y-')&lt;br&gt;
axis equal&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 19 Aug 2006 22:41:46 -0400</pubDate>
      <title>Draw a star.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/130807#329348</link>
      <author>Patrick Flaherty</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
Experienced programmer, but new to MatLab.&lt;br&gt;
&lt;br&gt;
How do I draw a simple 5-pointed star?&lt;br&gt;
&lt;br&gt;
Hope someone can help.&lt;br&gt;
&lt;br&gt;
pat&lt;br&gt;
&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
