kill(all)$
load(lrats)$

Envelope of projectile trajectories (=safety parabola ),version 1.0
peter.vlasschaert@gmail.com, 01/08/2018.

rem: see ' flat earth'  approximation 2D( = projectile motion ), '  = ref '

p1:sx=s0x+t*vx + ax*t^2/2;
p2:sy=s0y+t*vy + ay*t^2/2;

see : 'ref ', 'p1a,p2b', equations

gravity : neg downwards  y direction ( ay = -g), g=constant = 9.81 m/s^2
============================================================

initial cndition : v[0],x[0],y[0] , are constant.
----------------------------------------------------------------

p1a:[sx=x,s0x=x[0],vx=v[0]*cos(α),ax=0];
p1b:subst(p1a,p1);

p2a:[sy=y,s0y=y[0],vy=v[0]*sin(α),ay=-g];
p2b:subst(p2a,p2);

' p1b,p2b ' , =>  equation of 2D motion of projectile. ' see above '.

definition : safety parabola.
=======================

We fire projectile with speed ( = v[0]) ) and direction( = α),
determinate  'all' places of the region into 'xy plane we can reach'.

How to find : safety parabola ?
==========================

part 1 : elimination 't' from ' p1b,p2b  ' with x[0] =y[0] = 0 ( = origin)
--------------------------------------------------------------------------------------------------

p3 : [ x[0]=0,y[0]=0];
p3a:subst(p3,p1b);;
p3b: subst(p3,p2b);

p4:solve (p3a,t);

p4a:subst(p4,p3b);

p4b:[sin(α)/cos(α) = tan(α)];
p4c:lratsubst(p4b,p4a);

p4d:expand(p4c);

part 2: quadratic equation ,  tan(α).
----------------------------------------------------

rem : 1/cos(α)^2 = (cos(α)^2 +sin(α)^2 )/cos(α)^2 =(1+tan(α)^2);

p5:[1/cos(α)^2 =1+tan(α)^2];

p5a:lratsubst(p5,p4d);

p5b:expand(p5a);

p5c:lhs(p5b)-rhs(p5b)=0;

coef  ? : tan(α)^2,tan(α),constant.
--------------------------------------------------

1e)  coef :  'tan(α)^2'.
==================

p6:ratcoeff(lhs(p5c),tan(α)^2);

2e)  coef :  'tan(α)'.
===============

p6a:ratcoeff(lhs(p5c),tan(α));

3e)  coef :  'constant ', when tan(α) =0.
================================

p6b:subst([tan(α) =0],lhs(p5c));

p7:1/p6*p5c;

def : quadratic equation ,' tan(α)'
===========================

p7a:expand(p7);

    principle :  parabola.
%================%

rem :      a*M^2+b*M+c = 0 , M =tan(α)
           -------------------------------------------------
=>         discriminant  ?  ,  Δ = b^2-4*a*c
          --------------------------------------------------

rem  : point can be reached     into ' = xy plane ', roots  ' p7a' are real          , Δ ≥ 0.
            point can't be reached   into ' = xy plane ', roots 'p7a'  are complex , Δ < 0.

 %===============%

----------------------------------------------------------------------------------------
condition :  'saftey parabola '  at least one real root  , Δ =  0
=================================================

1e)  coef  : ' M =tan(α) '  =>  b

p8:b=ratcoeff(lhs(p7a),tan(α));

2e)  coef  : ' constant '  =>  c , when tan(α) =0

p8a:c=subst([tan(α)=0],lhs(p7a));

  =>  definition :discriminant  'Δ'
============================

p8b:Δ = b^2-4*a*c;

--------------------------------------------------

with use : Δ = 0, a=1,b,c  ' =  see above'

p8c:subst([Δ=0,p8,p8a,a=1],p8b);

region parabola = safety parabola : ' envelop ',can be reached .
====================================================

How  to solve  x^2  = k ? 
------------------------------------

p9:subst([x^2 = k],p8c);

p9a:expand(solve(p9,k));

equation : safety parabola ( back subst  k = x^2 into  'p9a').
==================================================

p9b:lratsubst([k=x^2],p9a)[1];

p9b1:expand(solve(p9b,y))[1];

Max : Y  = ' top ' , parabola               ? ,' ( x = 0 , into  p9b )  ' safety parabola '.
==============================================================

p10: subst([x=0,y=ymax],p9b);

p10a:solve(p10,ymax)[1];

Max : X = 'x ranges ',parabola        ? ,'(y=0,into p9b ), 'safety parabola '.
============================================================

p11:subst([ x = xmax,y=0],p9b);

p12:solve(p11,xmax);

p13:p12[1];
p13a:p12[2];

left  of  top  ' x ranges ' :  xmin
=========================

p14:xmin = rhs(p13);

right of  top  ' x ranges ' :  xmax
==========================

p14a:xmax=rhs(p13a);

elements : safety parabola
-----------------------------------------------------------------
-----------------------------------------------------------------

ranges x :  -v[0]^2/g  ≤ x ≤ v[0]^2/g
=============================

top           :  coordinate => (x=0, y=ymax)
=================================

------------------------------------------------------------------