matlab - Drawing a pentagon using a decagon -


I'm new to matlab and I'm stuck on one of my work, I have to draw a pentagram from a decimal , I am using a function called 'circle' which gives me all the coordinates of the desired circle, the function takes the coordinates of the center of the circle (cx, xi) and radius (r) and the number of vectors (n).

Here I would like to:

And how far away have I found it?

Here The 'circle' function code is:

  function [xx, yy] = circle (cx, cy, r, n) t = linspace (0, 2 * pi, n +1); X = r * because (t); Y = r * sin (t); Xx = x + cx; Yy = y + cy; End   

Here is the pentagram code:

  [x, y] = circle (0,0,5,5); [X1, y1] = circle (0,04,10); Px = [0 x (1) x1 (2) x (2) x1 (4) x (3) x1 (6) x (4) x1 (8) x (5) x1 (10)]; Py = [0 y (1) y1 (2) y (2) y1 (4) y (3) y1 (6) y (4) y1 (8) y (5) y1 (10)]; Plot (x, y, x1, y1, px, py); Axis ([- 11-11-11 11]); Axis is equal to;    

  function [xx, yy] = circle (cx, cy, r , N, phase) if nargin & lt; 5% check when phase logic step = 0 is provided; % If not - the default value is 0 end; T = linspace (0, 2 * p, n + 1); X = r * cos (T + step); Added% step to rotate coordinate y = R * sin (T + phase); % One xx = x + cx; Yy = y + cy; End   

and

  [x, y] = circle (0, 0, 5, 5); % Coordinates of points on the outer radius [x1, y1] = circle (0, 0, 1.5, 5, 2 * pi / 5/2); % Lower radius, equal number of digits, but rotated at half the angle between digits - for inner radius = px = zero (1, 2 * digit (x)); Prepare% vector where all x py = zero (1, 2 * digits (x)); % And y coordinate combined px (1: 2: end) = x; In an array px% interleave x value (2: 2: end) = x1; % Py (1: 2: end) = y with x1 values ​​in the same array; The same% for YP (2: 2: end) = y1; % And y1 plot (px, pA); % Plot pentagon rectangle ('position', [-5, -5, 10, 10], 'curvature', [1, 1]); % Axis around ([- 11 11-1111]); Axis is equal to;   

Result

Enter image details here

And another example. The idea is the same, but achieving on a simple mathematical basis is slightly different.

  n = 5; N1 = N + 1; R1 = 5; R2 = 1.5; Pi2 = pi / 2; Angle = linspace (0, 2 * pie, n1); Calcxy = @ (angle, r, shift, phase) shift + r * Cos (angle + phase); Px = zero (1, 2 * n1); PE = zero (1, 2 * N1); Indexed = 1: 2: 2 * n1; Px (indexed) = calcis (angle, r1, 0, 0); PE (indexed) = Kalsi (angle, r1, 0, - pi2); Indexed = 2: 2: 2 * n1; Px (indexed) = calcis (angles, r2, 0, 2 * pu2 / n); PE (indexed) = calcis (angle, r2, 0, 2 * pu2 / n - pi 2); Plot (px, pA); Rectangle ('position', [-R1, -r1, 2 * r1, 2 * r1], 'curvature', [1, 1]); Axis ([- 11-11-11 11]); Axis is equal to;   

for n = 10

Image Details Here Enter

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -