3
$\begingroup$

I'm trying to create a simulation of a person(line) walking along a wall(plane) with a lamppost behind the person(fixed point) that casts a shadow along the wall while the person is moving. I'm having a hard time understanding how to do this. I've created the person and the wall within a manipulate function already, I just don't know how to create the "shadow".

| improve this question | | | | |
$\endgroup$
3
$\begingroup$
height = 1/2;
comps = {floor, wall1, wall2};
lamp = {0, 0, 1};
person[px_, py_, high_] := {px, py, high}
ray[t_, px_, py_, high_] := lamp (1 - t) + t person[px, py, high]
MapThread[(#1[t1_, t2_] := #2) &, {comps, {{t1, t2, 0}, {1, t1, t2}, {t1, 1, t2}}}];

lims = Outer[#1[t1, t2] /. 
       First@Solve[ray[t, px, py, #2] == #1[t1, t2], {t, t1, t2}] &, comps, {0, height}];

objDraw[obj_] := Polygon[#[[Last[FindShortestTour@#]]] &@(obj @@ # & /@ 
                                                                  Tuples[{-1, 1}, 2])]

scene = Graphics3D[{objDraw /@ comps, Yellow, Sphere[lamp, .05]}, 
                   PlotRange -> {{-1, 1}, {-1, 1}, {0, 1}}];

Manipulate[Show[scene,
                Graphics3D[{Thickness[0.01], Black,
                Line[{person[Sequence @@ pos, 0],  person[Sequence @@ pos, height]}], 
                Gray,
                Quiet@Select[Line /@ (# /. Thread[{px, py} -> pos] & /@ lims), 
                             FreeQ[#, ComplexInfinity] &]}],
                Boxed -> False], 
          {pos, {-1, -1}, {1, 1}}]

enter image description here

| improve this answer | | | | |
$\endgroup$
2
$\begingroup$
Manipulate[
 dd = Norm[d];
 Graphics3D[
  {PointSize[0.04], Yellow, Point[{d[[1]], d[[2]], h}],
   {Black, Thickness[0.02], Line[{{0, 0, 0}, {0, 0, 1}}]},
   {Gray, Thickness[0.02], 
    Line[{{0, 0, 0}, 
          {-(h/(h - 1) - 1) d[[1]], -(h/(h - 1) - 1) d[[2]], 0}}]}},
  PlotRange -> {{-2, 2}, {-2, 2}, {0, 3}}],
 {d, {-.5, -.5}, {.5, .5}},
 {h, 1.2, 3, ControlType -> VerticalSlider, ControlPlacement -> Left}]
| improve this answer | | | | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.