# Stopping Integration by using RegionMember inside a WhenEvent

Posted 9 years ago
7288 Views
|
2 Replies
|
1 Total Likes
|
 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:
2 Replies
Sort By:
Posted 9 years ago
 You might Show the parabolic curve first, then the graphic of the house, which will block out the unwanted part of the stream. Set range {x,0,55} so stream does not reappear on other side of house. If you want to account for possibility for stream to go higher than house you can use full range for this condition.
Posted 9 years ago
 I realise that the unwanted part of the path can be visually hidden but I want to find out why WhenEvent does not stop the path entering inside the geometric region by using RegionMember. That, why I made the house very transparent so I can see if it works!