Simulate a polygon bouncing with collision detection inside a circle/polygon.
the example can be see in help page by searching WhenEvent
;
ball2d[r_?NumericQ] := Reap@NDSolveValue[{{x'[t] == vx[t], y'[t] == vy[t], x1'[t] == vx[t],
y1'[t] == vy[t]}, WhenEvent[{x[t]^2 + y[t]^2 == 1, x1[t]^2 + y1[t]^2 == .9}, {x1[t] ->
x[t] + (pp = RandomReal[.1]), y1[t] -> y[t] + Sqrt[0.02 - pp^2], vy[t] -> -.9 vy[t],
vx[t] -> -.9 vx[t]}],x[0] == 0, y[0] == 0, x1[0] == .1, y1[0] == .1, vx[0] == 1,
vy[0] == 1}, {x[t], y[t], x1[t], y1[t]}, {t, 0, 200},DiscreteVariables -> {vx, vy}];
{sol1, v} = ball2d[4/3];
Manipulate[ ParametricPlot[#, {t, 0, [Tau]}, Frame -> True, PlotRange -> 2,
PlotPoints -> 10, PlotStyle -> Thickness[0.02],Epilog -> {PointSize[.05], Point[# /. (t -> [Tau])],
ContourPlot[{x^2 + y^2 == 1}, {x, -1, 1}, {y, -1, 1}][[1]]}] & /@
Partition[sol1, 2], {{[Tau], 11.9}, 0.01, 198}, SaveDefinitions -> True]
The following example show a stick bouncing inside a circle, not so good
What's the right way?
How can I go forward to replace the stick with a triangle or a polygon? and futher a polygon3d?
Any examples?
Manipulate[ ParametricPlot[#, {t, 0, [Tau]}, Frame -> True, PlotRange -> 2,
PlotPoints -> 10, PlotStyle -> Thickness[0.0001],Epilog -> {Pink, Thick,
Line[{{#[[1]], #[[2]]}, {#[[3]], #[[4]]}}] /. (t -> [Tau]), ContourPlot[{x^2 + y^2 == 1}, {x, -1, 1}, {y, -1, 1}][[1]]}] &@
sol1, {{[Tau], 0.01}, 0.01, 198, .1}, SaveDefinitions -> True]
The reference posted by Mr.Wizard is about a point model which is much simpler. My question is about extending the example in WhenEvent
help page.
However the animation is really shown by that example, can you image a stick bouncing like that?