kill(all)$

flat earth : approxmation 2D version (projectile motion). 'version 1a'
peter.vlasschaert@gmail.com,08/06/2018

see: How to understand     :                motion equation 3D ,'version 1.0'

without : friction

3D motion (projectile), gravitation to xy plane (neg direction, az=-g)

p1a:sx=s0x+vx*t+ax*t^2/2;
p2b:sy=s0y+vy*t+ay*t^2/2;
p3c:sz=s0z+vy*t+az*t^2/2;

2D motion (projectile), gravitation to xy plane (neg direction, ay=-g)
s0x : initial position projectile ( x value) => sx : final position 
s0y : initial position projectile ( y value) => sy : final position

without losing generality :  (s0x=0,s0y=0, like fire projectile from the ground)

p1: p1a;
p2: p2b;

p3:s0x=0;
p4:s0y=0;

g=9.81 m/s^2 : fixed value.

p5a: sublis([p3],p1);
p5b: sublis([p4,ay=-g],p2);

initial velocity :  vx = vv0*cos(α)   ( x direction )
                              vy = vv0*cos(β)   ( y direction )
                              vv0 = fixed value = speed of fire the projectile
                              α = angle ( positive : x axis 'and' vector with magnitude = vv0   )
                              β = angle ( positive : y axis 'and' vector with magnitude = vv0   )

p6a : vx = vv0*cos(α);
p6b : vy = vv0*cos(β);

trig identity : 1e)  (cos(α))^2+(cos(β)) = 1
                         2e)  α + β =π/2

p7a:(cos(α))^2+(cos(β))^2 = 1;
p7b: α + β =%pi/2;
p7c : α + β -α = %pi/2-α;

ℏ;

mapping : cos on both sides.
operator : cos

p7d:map(cos,p7c);

find : magnitude 'vv0'  = speed of the projectile.
use : 'p6a,p6b'

p8a:p6a^2;
p8b:p6b^2;
p8c:p8a+p8b;
p8d: factor(p8c);

ratsubst : ' how to use '
find  : menu : simplify :substitute , option = rational
expression : p8d
Old   value     : lhs(p7a)
New value     : rhs(p7a)

ratsubst(rhs(p7a), lhs(p7a), p8d);

p8e:ratsubst(rhs(p7a), lhs(p7a), p8d);

magnitude : vv0 ?     'p8g'

p8f:solve(p8e,vv0);

select : pos 'sqr', ' second one ', launch speed for projectile fom origin.
     origin coordinates = (sx0,sy0) =(0,0)  ' xy plane '

p8g:p8f[2];

all things 'above' with put inside 'p5a,p5b'

p9a:sublis([p6a,p6b],p5a);
p9b:sublis([p6a,p6b],p5b);

sx = x  ' x position in the graph (xy plane)'
sy = y  ' y position in the graph (xy plane)'
use : 'p9a,p9b'

p9c:sx=x;
p9d:sy=y;

p10a: sublis([p9c,p9d],p9a);
p10b: sublis([p9c,p9d],p9b);

use : 'p7d' for  'cos(β)' => 'sin(α)'
rem :  ' not use sublis' use 'ratsubst' = 'see above'

p11a:ratsubst(rhs(p7d),lhs(p7d),p10a);
p11b:ratsubst(rhs(p7d),lhs(p7d),p10b);

because : no acceleration ' x direction ' , (ax=0)

p12a:ax=0;
p12b:sublis([p12a],p11a);
p12c:sublis([p12a],p11b);

rem : pair of equations 'p12b,p12c' of 2D motion.

how to find : graph y=y(x) , rmove 't'  from 'p12b'

p13a: solve(p12b,t);

p13b:sublis(p13a,p12c);

rem : fullratsimp 'use also'

we see:  y = a*x^2+b*x+c ?  parabola
? a,b,c  from 'p13c'

1e) expand 'p13c'

p13d:expand(p13b);

2e) find a,b,c 

p14a: a=coeff(rhs(p13d),x^2);
p14b: b=coeff(rhs(p13d),x);
p14c: c=ev(rhs(p13d),x=0);

rem : x=0 : 'see above' => y=0

parametric plot (x(t),y(t))
x=x(t)
y=y(t)

p15:[α=%pi/3,vv0=2.0,g=9.81];
p15a: sublis(p15,p12b);
p15b: expand(sublis(p15,p12c));

p15a ' linear eq. through origin,t'
p15b ' parobola                            ,t'

graph : x(t),y(t)

wxdraw2d(xaxis = true,yaxis=true,grid=true,explicit(rhs(p15a),t,-0.02,0.5),xlabel="t (s)",
ylabel="x (m)")$
 wxdraw2d(xaxis = true,yaxis=true,grid=true,explicit(rhs(p15b),t,-0.02,0.5),xlabel="t (s)",
ylabel="y (m)")$

makelist : x,y values. (some ,t values  range)

vb:makelist(ev([rhs(p15a),rhs(p15b)]),t,-0.1,0.5,0.01)$

wxplot2d([discrete,vb],[style,[lines,3,red]]);

wxplot2d([discrete,vb],[style,[points,1,green]]);

p16a:makelist(ev([rhs(p15a),rhs(p15b)]),t,0,0.5,0.1)$

p16b:float(p16a);

you can use : permanent function 

x :x(t)=qx(t)
y :y(t)=qy(t)

qx(t):=''(rhs(p15a));
qy(t):=''(rhs(p15b));

how to use:

p16c:qy(0.35);

p16d:float(p16c);

ℏ;

when we want : angle = degree , conversion  'rad' to 'degree =dg' : π/180

dg:%pi/180$
a1: print(" use degree :conversion ,sin(60) =  ",sin(60*dg));

? When projectile hit the ground :  ' use p12b,p12c' 
answer : y=0 , gives flight time.=t_flight

1e) t_flight :

p17a:solve(rhs(p12c)=0,t);

p17b:p17a[1]$
p17c:subst([t=t_flight],p17b);

rem : t=0 ,point to start projectile  (see 'p17a')

2e) distance : horizontal ground  : 0 to x_impact
answer : t_flight into 'p12b'

p17d:x_impact =sublis([t =rhs(p17c)],rhs(p12b));

given : vv0 =2,α=π/3,g=9.81 => x_impactvalue,t_flightvalue.

p17e:x_impactvalue = float(sublis(p15,rhs(p17d)));

p17f:t_flightvalue = float(sublis(p15,rhs(p17c)));

wxdraw2d(xaxis = true,yaxis=true,grid=true,explicit(rhs(p15a),t,-0.02,rhs(p17f)+0.015),xlabel="t (s)",
ylabel="x (m)")$
 wxdraw2d(xaxis = true,yaxis=true,grid=true,explicit(rhs(p15b),t,-0.02,rhs(p17f)+0.015),xlabel="t (s)",
ylabel="y (m)")$

?   Max height for projectile.
answer : dy/dt = 0 ,t_high : time to reach that  point.

1e) find t_high ?

p18a:diff(rhs(p12c),t)=0;

p18b:solve(p18a,t)[1]$
p18c:subst(t=t_high,p18b);

2e) find Max height : h_max ?

p18d:subst([t=rhs(p18c)],p12c)$
p18e:sublis([y=h_max],p18d);

given : vv0 =2,α=π/3,g=9.81 => h_maxvalue,t_highvalue.

p18d:t_highvalue=float(sublis(p15,rhs(p18c)));

p18e:h_maxvalue=float(sublis(p15,rhs(p18e)));

interactive graph : example : ' see above'

given : vv0 =2,α=π/3,g=9.81 

non interactive graph :

p19a:[ylabel,"f(t)"];
p19b:[xlabel,"time"];
p19c:[y,-0.1,0.3];
p19d:[legend,"qx(t)","qy(t)","t axes","y=h.maxvalue"];

wxplot2d([qx, qy,0,rhs(p18e)],[t,-0.02,.5], [plot_format, xmaxima],p19a,p19b,p19c,p19d)$

interactive graph      :

plot2d([qx, qy,0,rhs(p18e)],[t,-0.02,.5], [plot_format, xmaxima]);

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