you will have learned that the resulting Sierpinski triangle provides a selfsimi
ID: 3530899 • Letter: Y
Question
you will have learned that the resulting Sierpinski triangle provides a selfsimilar surface, where certain geometric features repeat over and over. You may also have observed that the geometry changes at the midpoint of each triangle edge, knowledge that you can use to write a subdivision algorithm using the following pseudo code (a) Define the three vertices of the triangle (e.g. v1 = [0 0], v2=[1 0] ; v3 = [0.5 sqrt(3)/2]). (b) For each of the three triangle edges, find the midpoint and plot it. (c) Subdivide the original triangle into four (imagine connecting the midpoints). (d) For each of the three smaller corner triangles repeat from step (b). (e) Terminate when a specified number of recursions has been reached. Use the following for your recursive function: function [] = sierpinski_recursive(v1, v2, v3, reclevel) Hint: Generally, matlab will wait with printing your points until the recursive call has been completed. You can force matlab to update its active figure by callingExplanation / Answer
midpoint[p1_, p2_] := Mean[{p1, p2}] trianglesurface[A_, B_, C_] := Graphics[Polygon[{A, B, C}]] sierpinski[A_, B_, C_, 0] := trianglesurface[A, B, C] sierpinski[A_, B_, C_, n_Integer] := Show[ sierpinski[A, midpoint[A, B], midpoint[C, A], n - 1], sierpinski[B, midpoint[A, B], midpoint[B, C], n - 1], sierpinski[C, midpoint[C, A], midpoint[C, B], n - 1] ]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.