Advertisement
Matthen

Crossing the road- smooth version

Jun 12th, 2013
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. h = 3.5;
  2. Needs["VariationalMethods`"];
  3. Unset[x];
  4. frame[dip_] := Module[{eqn, soln},
  5. c[x_] :=
  6. 1 - dip ((1 + Tanh[5 (x + 0.7)])/2 - (1 + Tanh[5 (x - 0.7)])/2 +
  7. 0.1 Exp[-10 x^2]);
  8. eqn = EulerEquations[Sqrt[1 + y'[x]^2]/c[x], y[x], x];
  9. soln =
  10. First[NDSolve[{eqn, y[-1] == 0, y[1] == h}, y[x], {x, -1, 1}]];
  11. Show[
  12. Graphics[{
  13. Table[
  14. {Lighter@ColorData["LightTemperatureMap"][1 - c[x]],
  15. Rectangle[{x, -0.1}, {x + 0.1, h + 0.1}]}
  16. , {x, -1.1, 1.1, 0.05}],
  17. {RGBColor[0.62, 0.15, 0.2], Disk[{-1, 0}, 0.1],
  18. Disk[{1, h}, 0.1]}
  19. }
  20. , PlotRange -> {{-1.1, 1.1}, {-0.1, h + 0.1}},
  21. AspectRatio -> h/2],
  22.  
  23. Plot[{Evaluate[y[x] /. soln], Evaluate[y[x] /. soln]}, {x, -1, 1},
  24. PlotStyle -> {Directive[Thickness[0.05],
  25. RGBColor[0.62, 0.15, 0.2]], Directive[White]}]
  26. ]
  27. ];
  28. frame[0.3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement