Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

35) In Problem 5.9-7 you are to generalize the spiral triangle script file spiral_triangle to a regular polygon with m sides for any m >

image text in transcribed
image text in transcribed
image text in transcribed
35) In Problem 5.9-7 you are to generalize the spiral triangle script file spiral_triangle to a regular polygon with m sides for any m > 3 by modifying the script file "slightly". a) Convert this script file to the function fspiralgon whose input arguments are m, n, d_angle, rotate, and shift, so take out statements (1,2). The fourth input argument rotates the initial polygon, i.e., the inner one, by an additional rotate degrees, and the fifth argument shift shifts the center of all these polygons to the point (shift(1), shift(2)). (i) Plot a spiral square for n 41 and d_angle = 2.250, then for n 21 and d_angle = 4.5, and finally for for n= 11 and d_angle = 9. However, it should look like a square and not a diamond, i.e., the sides should start end end perfectly horizontal and vertical (ii) Repeat the above images, but the square should rotate 180 by "doubling" n. (iii) Plot a spiral pentagon which rotates a total of 180. Use "pleasing" values of n and d angle. (iv) Plot a spiral octagon which rotates a total of 360. Use "pleasing" values of n and d angle. b) We now return to the spiral square. Write a code so it can generate a kxk square of squares for any k > 1 without any change in the code (other than modifying the value of k). (i) Put four of them together to form a larger square shown in Figure 6.28(a). (b) Figure 6.28: (a) Four spiral squares combined. (b) A spiral duodecagon, which is similar to the spiral triangle shown in Figure 5.4. However, the non-red colors are concentrated near the center, so the shape isn't as "pleasing as it might be. c) (i) Then put sixteen of them together. The graphical image shown below is generated by the following code where n=21 and d_angle = 4.5. % script m-file: spiral_triangle % input: n = the number of triangles d_angle = the angle between successive triangles (can be positive or negative) % output: V = the vertices of the outermost triangle th = linspace(0, 360, 4) + 90; % (1) V = [cosd(th) sind(th)]; C = colormap(hsv(n)); scale = sind(150 - abs (d_angle))/sind (30); R = rot 2(d_angle); % (in ch4files) hold off for i = 1:n if i > 1 y = scale*R*V; end Figure 5.4: A spiral plot (V(1, :), V(2,:), 'Color', C(i, :)) % (11) triangle. hold on % (12) end % (13) set (gcf, 'Color', 'w') % (14) axis equal axis off % (16) shg % (17) % (15) 35) In Problem 5.9-7 you are to generalize the spiral triangle script file spiral_triangle to a regular polygon with m sides for any m > 3 by modifying the script file "slightly". a) Convert this script file to the function fspiralgon whose input arguments are m, n, d_angle, rotate, and shift, so take out statements (1,2). The fourth input argument rotates the initial polygon, i.e., the inner one, by an additional rotate degrees, and the fifth argument shift shifts the center of all these polygons to the point (shift(1), shift(2)). (i) Plot a spiral square for n 41 and d_angle = 2.250, then for n 21 and d_angle = 4.5, and finally for for n= 11 and d_angle = 9. However, it should look like a square and not a diamond, i.e., the sides should start end end perfectly horizontal and vertical (ii) Repeat the above images, but the square should rotate 180 by "doubling" n. (iii) Plot a spiral pentagon which rotates a total of 180. Use "pleasing" values of n and d angle. (iv) Plot a spiral octagon which rotates a total of 360. Use "pleasing" values of n and d angle. b) We now return to the spiral square. Write a code so it can generate a kxk square of squares for any k > 1 without any change in the code (other than modifying the value of k). (i) Put four of them together to form a larger square shown in Figure 6.28(a). (b) Figure 6.28: (a) Four spiral squares combined. (b) A spiral duodecagon, which is similar to the spiral triangle shown in Figure 5.4. However, the non-red colors are concentrated near the center, so the shape isn't as "pleasing as it might be. c) (i) Then put sixteen of them together. The graphical image shown below is generated by the following code where n=21 and d_angle = 4.5. % script m-file: spiral_triangle % input: n = the number of triangles d_angle = the angle between successive triangles (can be positive or negative) % output: V = the vertices of the outermost triangle th = linspace(0, 360, 4) + 90; % (1) V = [cosd(th) sind(th)]; C = colormap(hsv(n)); scale = sind(150 - abs (d_angle))/sind (30); R = rot 2(d_angle); % (in ch4files) hold off for i = 1:n if i > 1 y = scale*R*V; end Figure 5.4: A spiral plot (V(1, :), V(2,:), 'Color', C(i, :)) % (11) triangle. hold on % (12) end % (13) set (gcf, 'Color', 'w') % (14) axis equal axis off % (16) shg % (17) % (15)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions

Question

Name and accurately describe two projective tests.

Answered: 1 week ago