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".
2
-
$\begingroup$ Have you seen this? $\endgroup$ – J. M.'s ennui♦ Mar 12 '16 at 3:08
-
1$\begingroup$ Please include the code you have tried. $\endgroup$ – bbgodfrey Mar 12 '16 at 5:13
Add a comment
|
$\begingroup$
$\endgroup$
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}}]
$\begingroup$
$\endgroup$
0
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}]