Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. poly[n_, e_] := Table[
  2. {2 e + e Cos[2.0 Pi (i + 0.5) / n]/2, Sin[2.0 Pi (i + 0.5) /n]/2}
  3. , {i, n + 1}];
  4. lengths[n_, e_] := With[{p = poly[n, e]},
  5. Map[
  6. Norm[First[#] - Last[#]] &,
  7. Transpose[{p[[2 ;;]], p[[;; -2]]}]
  8. ]
  9. ];
  10. length[n_, e_] := Total[lengths[n, e]];
  11. Manipulate[
  12. Module[{p, acc},
  13. p = poly[n, e];
  14. acc = Join[{0}, Accumulate[lengths[n, e]]];
  15. Show[{
  16. Graphics[{
  17. {
  18. Table[
  19. {GrayLevel[0.7], Line[{{0, y}, {2, y}}],
  20. Black,
  21. Text[Style[y, FontSize -> Medium], {-0.1, y}]
  22. }
  23. , {y, {0.5, 1, 1.5, 2.0, 2.5, 3.0, Pi}}]
  24. },
  25.  
  26. Point[{2 e, 0}],
  27. Point[{2 e, length[n, e]}],
  28.  
  29. Table[
  30. {
  31. PointSize[Large],
  32. Thick,
  33. ColorData["DarkRainbow"][i/n],
  34. Line[{{2 e, acc[[i]]}, {2 e, acc[[i + 1]]}}],
  35. Point[{2 e, acc[[i]]}],
  36. Point[p[[i]]],
  37. Line[{p[[i]], p[[i + 1]]}]
  38. },
  39. {i, Length[acc] - 1}
  40. ]
  41. }, PlotRange -> {{-0.4, 2.6}, {-0.6, 3.2}}],
  42. Plot[{
  43. length[n, et/2]
  44. }, {et, 0, 2}, PlotRange -> All]
  45. }]
  46. ],
  47. {n, 3, 20, 1},
  48. {{e, 1}, 0.01, 1}
  49. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement