Advertisement
Matthen

Visual proof of geometric sum

May 6th, 2016
1,983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Clear[p]; Clear[s]; Clear[triangle];
  2. triangle[s_, {x_, y_}, \[Theta]_] :=
  3. Table[{x, y} +
  4. s {Sin[\[Theta] + 2 Pi i/3.0], Cos[\[Theta] + 2 Pi i/3.0]}, {i,
  5. 3}];
  6. p[1] = {0, 0};
  7. s[1] = 1;
  8. s[n_] := s[n] = s[n - 1]/2 ;
  9. p[n_] := p[n] =
  10. p[n - 1] +
  11. RotationMatrix[-n Pi / 3].{Sqrt[3] s[n]/2.0, s[n - 1] - s[n]/2};
  12. triangle[n_] := triangle[s[n], p[n], If[Mod[n, 2] == 1, 0, Pi/3]];
  13.  
  14. cols = ColorData["Rainbow"] /@ {0.25, 0.5, 0.75};
  15. Manipulate[
  16. Graphics[{
  17. {FaceForm[], EdgeForm[Black], Polygon[triangle[2, {0, -1}, 0]]},
  18. If[m < 1, {},
  19. {{
  20. FaceForm[cols[[1]]], EdgeForm[Darker@cols[[1]]],
  21. Table[Polygon[triangle[n]], {n, Max[0, Floor[(m - 1)/3]]}]},
  22. {FaceForm[cols[[2]]], EdgeForm[Darker@cols[[2]]],
  23. Translate[
  24. Rotate[Table[Polygon[triangle[n]], {n, Floor[m/3]}],
  25. 2 Pi/3, {0, 0}], {-Sqrt[3]/2, -1.5}]},
  26. {FaceForm[cols[[3]]], EdgeForm[Darker@cols[[3]]],
  27. Translate[
  28. Rotate[Table[
  29. Polygon[triangle[n]], {n, Max[0, Floor[(m + 1)/3]]}], -2 Pi/
  30. 3, {0, 0}], {Sqrt[3]/2, -1.5}]}}
  31. ]
  32. }, PlotRange -> All, ImagePadding -> 10],
  33. {m, 1, 30, 1}
  34. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement