I assume the 'cos(theta),sin(theta)' bit was as in
e^(i*theta) = cos(theta) + i*sin(theta)?
And playing with the code below a bit, the 4/5s and
the 4 (defining the theta range) are what get you
the 5-pointed star? Although exactly how this works,
I'm not yet sure. (but Matlab is a great tool for
just playing with things [and learning them thereby]).
That was the warm-up. I'm actually trying to work on
a homework problem for my wife's eldest brother's eldest
son. The son is now in his first year at a technical
university. The program is bio-chemical engineering but
of course he needs to learn to program and is doing
so for the first time.
I'm a programmer and so I'd been helping him out already,
when he was first using SciLab. Which, as best I could make
out (and I hadn't seen SciLab before either) is maybe
something like a student version of Matlab.
He's in Malaysia (my wife's from Malaysia).
The actual problem is to recreate the star that's in the upper
left of the Malaysian flag (drawing it in Matlab of course).
The star, that is, that's just to the right of the crescent
moon (Muslim symbolism).
However the star there is 14-pointed (not 5). I tried switching
the 4/5 and 4 in your code to 14/15 and 14 and I got something
vaguely like a 14-pointed star except that there was a '15th'
point which didn't close at its tip. Maybe the odd and even
(number of points) cases differ ...
In accomplishing the task, the hmwk gives a small amount
of (doubtless invaluable) information.
1. start by defining two vectors of complex #s Zsub1 = r*e^(i*theta)
and rsubZsub2 = 0.5*rsubZsub1
(Thus r diminishing by 1/2 with each subsequent term.)
and 2. normalize the scales with a third Zsub3 where
Zsub3*(2n-1) = Zsub1*(n).
pat
In article
<ellieandrogerxyzzy-2008061008490001@dialup-4.232.60.187.dial1.losangeles1.level3.net>,
Roger Stafford says...
>
>theta = 0:4/5*pi:4*pi;
>plot(cos(theta),sin(theta),'y-')
>axis equal
>
>Roger Stafford
In article <ecau8b0197n@drn.newsguy.com>, Patrick Flaherty
<Patrick_member@newsguy.com> wrote:
> ....
> However the star there is 14-pointed (not 5).
> ....
----------------------------
The Malaysian fourteen-pointed star is a bit more of a challenge.
% The rectanglar background
a = 80; b = 60;
x1 = [a,-a,-a,a,a];
y1 = [b,b,-b,-b,b];
% The star
t = (-1/4:1/28:3/4)*2*pi;
r1 = 44; r2 = 19;
r = (r1+r2)/2 + (r1-r2)/2*(-1).^[0:28];
x2 = r.*cos(t);
y2 = r.*sin(t);
% Fill the polygons
fill(x1,y1,'b',x2,y2,'y')
axis equal
Brief description: x1 and y1 trace out a 160 by 120 rectangular polygon.
The angle t progresses from -pi/2 to +3/2*pi in steps of 2*pi/28 for the
28 line segments of the star, while r alternates between radius 44 and
19. x2 and y2 have the coordinates of the alternate outer and inner
successive points of the polygon defining the star. The 'fill' command
first draws a blue rectangle and then superimposes the yellow star. 'axis
equal' ensures that scaling is equal between the x and y axes in the plot.
My advice to you would be, not to give your nephew the above complete
code, but to describe in broad terms the nature of the steps involved and
let him work out the details: how to generate polygonal points on two
different circles using an angle t and a radius r which alternates between
two fixed radii; then the conversion to cartesian coordinates x =
r.*cos(t) and y = r.*sin(t); and finally how the 'fill' function is used
to fill the interior of polygons with selected colors. He will learn more
if he has to do some of the work.
In article
<ellieandrogerxyzzy-2008062041000001@dialup-4.232.6.13.dial1.losangeles1.level3.net>,
Roger Stafford says...
>
>In article <ecau8b0197n@drn.newsguy.com>, Patrick Flaherty
><Patrick_member@newsguy.com> wrote:
>
>> ....
>> However the star there is 14-pointed (not 5).
>> ....
>----------------------------
> The Malaysian fourteen-pointed star is a bit more of a challenge.
>
> ....
Much thanx Roger. You're more than generous with both your time
and explanation.
A further question though if I might. I understand reasonably the
code and explanation you give. It's my impression though that this
method is considerably different from what the professor indicated in
his hints - using 2 complex vectors; e^(i*theta),etc; and a third
complex vector to normalize the axes.
Briefly, as best I understand, you're sweeping out a clock-like motion,
moving in-and-out for each node (point) and edge. Whereas what the
professor was suggesting (I believe) was something more like deforming
a circle into the required star shape.
In article <ecbin502r8a@drn.newsguy.com>, Patrick Flaherty
<Patrick_member@newsguy.com> wrote:
> .....
> A further question though if I might. I understand reasonably the
> code and explanation you give. It's my impression though that this
> method is considerably different from what the professor indicated in
> his hints - using 2 complex vectors; e^(i*theta),etc; and a third
> complex vector to normalize the axes.
> ......
> pat
-----------------------
Writing v = r.*exp(i*theta)), x = real(v), y = imag(v) is equivalent to
saying x = r.*cos(theta) and y = r.*sin(t).
It is possible the professor was hinting at something like the following
to achieve the desired change of radius using two rotating vectors, one at
the end of the other:
theta = (-1/4:1/28:3/4)*2*pi; % The slow rotation
phi = (0:28)*pi; % The rapid rotation
v = (r1+r2)/2*exp(i*theta) + (r1-r2)/2*exp(i*(theta+phi));
x = real(v); y = imag(v);
At each step the angle theta changes by pi/14 or 1/28 of a revolution,
while phi changes by a half a revolution, so theta+phi changes by
1/28+1/2=15/28 of a revolution. It is a rotation of one vector about the
end of another longer, more slowly rotating vector. It adds up to the
same effect as using r = (r1+r2)/2 + (r1-r2)/2*(-1).^[0:28] which
alternates between r1 and r2 in radius.
I don't know what he planned for the third vector to normalize the
axes. I can't think of anything in matlab that would work to ensure the
units along the two axes are of the same length except a specific
reference to the 'axes' function or its equivalent, such as 'axes equal'.
ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)
wrote in message
<ellieandrogerxyzzy-2008061008490001@dialup-4.232.60.187.dial1.losangeles1.level3.net>...
> theta = 0:4/5*pi:4*pi;
> plot(cos(theta),sin(theta),'y-')
> axis equal
>
> Roger Stafford
How can i fill this star with colour? Make it a coloured star.
"Ionut Plesa" <hartson9@k.ro> wrote in message <fkc8vb$7rg
$1@fred.mathworks.com>...
> ellieandrogerxyzzy@mindspring.com.invalid (Roger Stafford)
> wrote in message
>
<ellieandrogerxyzzy-2008061008490001@dialup-4.232.60.187.dial1.losan
geles1.level3.net>...
> > theta = 0:4/5*pi:4*pi;
> > plot(cos(theta),sin(theta),'y-')
> > axis equal
> >
> > Roger Stafford
> How can i fill this star with colour? Make it a coloured star.
---------
Matlab's 'fill' instruction interprets the area inside the star's inner pentagon
as being outside the fill area, since it is inside "twice", so to speak. Therefore
that pentagon area doesn't get filled. My solution would be to rewrite the
program so that the polygon doesn't cross itself, something along the lines of
the fourteen-pointed star method earlier in this thread. Similarly to that
problem, fix it so that the polygon alternates repeatedly between the r1 and
r2 radii as theta increases from 0 to 2*pi.
theta = 0:2/10*pi:2*pi;
r1 = 1; r2 = cos(2*pi/5)/cos(pi/5);
r = (r1+r2)/2 + (r1-r2)/2*(-1).^[0:10];
x = r.*cos(theta); y = r.*sin(theta);
fill(x,y,'y')
axis equal
Roger Stafford
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
What are tags?
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.