Advertisement
Matthen

Crossing the road

May 20th, 2013
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. hmax = 2;
  2. Cost[h_, y_, \[Lambda]_] :=
  3. With[{p1 = {-1, 0}, p2 = {-0.8, y}, p3 = {0.8, h - y}, p4 = {1, h}},
  4. Norm[p2 - p1] + Norm[p3 - p2] + Norm[p4 - p3] +
  5. \[Lambda] Norm[p3 - p2]
  6. ];
  7. Manipulate[
  8. Block[{yo, n},
  9. yo = yt /. (Minimize[Cost[h, yt, \[Lambda]], yt][[2]]);
  10. With[{p1 = {-1, 0}, p2 = {-0.8, y}, p3 = {0.8, h - y}, p4 = {1, h},
  11. p2o = {-0.8, yo}, p3o = {0.8, h - yo}},
  12. n = Sin[VectorAngle[p2o - p1, {-1, 0}]]/
  13. Sin[VectorAngle[p3o - p2o, {-1, 0}]];
  14. Graphics[{
  15. GrayLevel[0.7],
  16. Rectangle[{-1, -0.5}, {1, hmax + 0.5}],
  17. GrayLevel[0.5],
  18. Rectangle[{-0.8, -0.5}, {0.8, hmax + 0.5}],
  19. PointSize[Large], Blue, Point[p1], Red, Point[p4],
  20. (*Black,Point[p2],Point[p3],Line[{p1,p2,p3,p4}],*)
  21. Dashed,
  22. Purple, Point[p2o], Point[p3o], Line[{p1, p2o, p3o, p4}]
  23. }]
  24. ]
  25. ],
  26. {{\[Lambda], 1}, 0, 5}
  27. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement