#
import matplotlib.pyplot as PLT
import numpy as NUM
#
print('')
print('*** Waagerechter Wurf')
print('')
#
# Make Data:
G = 9.81  # [m/s2] - Erdbeschleunigung
X0 = 2.0  # [m] - X-Startpunkt
Y0 = 10.0  # [m] - Y-Startpunkt
V0X = 4.2 # [m/s] - Startgeschwindigkeit X-Richtung
#
VT = NUM.linspace(0, 1.5, 30)          # [s] - Zeitvektor
VVX = NUM.linspace(V0X, V0X, 30)       # [m/s] - Geschwindigkeitsvektor X
VVY = -G * VT                          # [m/s] - Geschwindigkeitsvektor Y
VX = VVX * VT + X0                     # [m] - Ortsvektor X
VY = Y0 - 0.5 * G * VT * VT            # [m] - Ortsvektor Y
VCY = Y0 - G * (VX - X0) * (VX - X0) / 2 / V0X / V0X # Bahnkurve CY = Y(X)
#
# Wurfweite xw [m]
XW = X0 + V0X * NUM.sqrt(2 * Y0 / G)
print('Wurfweite xw = {0} m'.format(XW))
# Wurfdauer td [s]
TD = (XW - X0) / V0X
print('Wurfdauer td = {0} s'.format(TD))
# Aufprallgeschwindigkeit vp [m/s]
VP = NUM.sqrt(V0X * V0X + G * G / V0X / V0X * (XW - X0) * (XW - X0))
print('Aufprallgeschwindigkeit vp = {0} m/s'.format(VP))
#
# Make Plot:
#------------------------------------------------
Figure, (A1, A2) = PLT.subplots(1, 2)
Figure.set_size_inches(12, 8)
#
A1.plot(VT, VX, 'b')
A1.plot(VT, VX, 'ob')
A1.set_title('x(t)')
A1.set(xlabel='t [s]', ylabel='x [m]')
A1.grid(True)
#
A2.plot(VT, VVX, 'g')
A2.plot(VT, VVX, 'go')
A2.set_title('vx(t)')
A2.set(xlabel='t [s]', ylabel='vx [m/s]')
A2.grid(True)
#
PLT.show()
#------------------------------------------------

Figure, (A3, A4) = PLT.subplots(1, 2)
Figure.set_size_inches(12, 8)
#
A3.plot(VT, VY, 'b')
A3.plot(VT, VY, 'ob')
A3.set_title('y(t)')
A3.set(xlabel='t [s]', ylabel='y [m]')
A3.grid(True)
#
A4.plot(VT, VVY, 'g')
A4.plot(VT, VVY, 'go')
A4.set_title('vy(t)')
A4.set(xlabel='t [s]', ylabel='vy [m/s]')
A4.grid(True)
#
PLT.show()
#------------------------------------------------
#
Figure, Axes = PLT.subplots()
Figure.set_size_inches(12, 8)
#
Axes.plot(VX, VY, 'b')
Axes.plot(VX, VCY, 'or')
Axes.set_title('y = y(x)')
Axes.set(xlabel='x [m]', ylabel='y [m]')
Axes.grid(True)
#
PLT.show()
#
