According to the definition of StadiumShape[{{x1, y1}, {x2, y2}}, r], the distance to the Line[{{x1,y1}, {x2,y2}}] less equal to r.
When the r is small enough( r<= 1/2 the length of line {x1,y1},{x2,y2}), to get the boundary of StadiumShape one can simple replace less equal to equal.
eqn = RegionDistance[Line[{{-1, 0}, {1, 0}}], {x, y}] == 1

reg = ImplicitRegion[eqn, {x, y}]
RegionPlot[reg, AspectRatio -> Automatic]

Clear["Global`*"];
reflect[vector_,
normal_] = -(vector - 2 (vector - Projection[vector, normal])) //
Simplify;
R = StadiumShape[{{-1, 0}, {1, 0}}, 1];
R2 = RegionBoundary[R];
dist = RegionDistance[R2];
proj = RegionNearest[R2];
pt0 = RandomPoint[R, 1][[1]];
v0 = {1., 2.};
d0 = 0.01*Norm[v0];
sol = NDSolveValue[{r''[t] == {0, 0}, r[0] == pt0, r'[0] == v0,
WhenEvent[dist@r[t] <= d0,
r'[t] -> reflect[r'[t], r[t] - proj@r[t]]]}, r, {t, 0, 100},
MaxStepSize -> 0.01];
ani = Animate[
Show[Graphics[{{FaceForm[Darker@Green], EdgeForm[Cyan], R}}],
ParametricPlot[sol@t, {t, 0, c}, Mesh -> {{c}},
MeshStyle -> {AbsolutePointSize[8], Red},
Method -> {"BoundaryOffset" -> False},
PlotStyle -> {Opacity[.9], White}, PlotPoints -> 80,
PerformanceGoal -> "Quality", PlotRange -> All] /. Line -> Arrow,
Background -> LightGray, PlotRange -> 2], {c, $MachineEpsilon,
100}, AnimationRate -> 1, ControlPlacement -> Bottom]

δ = 1;
ani = Animate[
Show[Graphics[{{FaceForm[Darker@Green], EdgeForm[Cyan], R}}],
ParametricPlot[sol@t, {t, c - δ, c}, Mesh -> {{c}},
MeshStyle -> {AbsolutePointSize[8], Red},
Method -> {"BoundaryOffset" -> False},
PlotStyle -> {Opacity[.9], White}, PlotPoints -> 80,
PerformanceGoal -> "Quality", PlotRange -> All] /. Line -> Arrow,
Background -> LightGray,
PlotRange -> 2], {c, $MachineEpsilon + δ, 100},
AnimationRate -> 1, ControlPlacement -> Bottom]

StadiumShapeto plot the diagram. But I want to use a proper mathematical equation to plot it. Like they show in DESMOS (https://www.desmos.com/calculator/1hjfojqisv) – user444 Nov 24 '22 at 05:18