I want to use the new geometric region functions of version 10 to stop integration inside NDSolve by using WhenEvent. I want the path of a projectile to stop at the border of a house represented by a geometric region.
This code is the differential equation modelling a projectile being fired under the influence of gravity only.
deqns[s_, \[Theta]_, d_] :=
{x''[t] == 0, y''[t] == - 9.81,
x[0] == 10 Cos[\[Theta]], y[0] == 10 Sin[\[Theta]],
x'[0] == s Cos[\[Theta]], y'[0] == s Sin[\[Theta]]}
This code demonstrates the path of a projectile being fired at a house. The house is a geometric region. The parabolic path is supposed to stop by means of a WhenEvent at the border of the region by using RegionMember as a predicate.
Manipulate[
Quiet@Module[{pts, house, sol},
pts = {d, 0} + # & /@ {{50, 0}, {50, 20}, {62.5, 30}, {75,
20}, {75, 10}, {90, 10}, {90, 0}};
house = MeshRegion[pts, Polygon[Range[Length@pts]]];
sol = NDSolve[{deqns[s, \[Theta], d],
WhenEvent[RegionMember[house, {x[t], y[t]}], "StopIntegration";
tend = t]}, {x, y}, {t, 0, 10}][[1]];
ParametricPlot[{x[t], y[t]} /. sol, {t, 0, tend},
PlotRange -> {{0, 100}, {0, 50}}, PlotStyle -> Blue,
Epilog -> {{EdgeForm[Black], FaceForm[Opacity[0.1]],
Polygon[pts]}, Red, Thickness[.01],
Line[{{0, 0}, 10 {Cos[\[Theta]], Sin[\[Theta]]}}]}]],
{{d, 3.5, "distance to house"}, -30, 10, Appearance -> "Labeled"},
{{s, 26, "water pressure"}, 0, 40, Appearance -> "Labeled"},
{{\[Theta], .87, "fire hose angle"}, .15, 1.5,
Appearance -> "Labeled"}, TrackedSymbols :> True]
Maybe somebody can help me find out or explain why this code does not always work?
Attachments: