# File:Inclinedthrow.gif

Inclinedthrow.gif(400 × 288 pixels, file size: 374 KB, MIME type: image/gif, looped, 102 frames, 10 s)

## Summary

Description
English: Trajectories of three objects thrown at the same angle (70°). The black object doesn't experience any form of drag and moves along a parabola. The blue object experiences Stokes' drag, and the green object Newton drag.
Date 15 December 2008
Source Own work
Author AllenMcC.
Other versions Inclinedthrow2.gif
GIF development

## Python

```#!/usr/bin/python3
# -*- coding: utf8 -*-

import os
import inspect
from math import *
import numpy as np
from scipy.integrate import odeint
from scipy.optimize import newton
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import animation

# settings
mpl.rcParams['path.snap'] = False
fname = 'inclinedthrow'
size = 400, 288
l, w, b, h = 22.5/size, 1-23/size, 22.5/size, 1-23/size
nframes = 102
delay = 8
lw = 1.
ms = 6
c1, c2, c3 = "#000000", "#0000ff", "#007100"

def projectile_motion(g, mu, pot, xy0, vxy0, tt):
# use a four-dimensional vector function vec = [x, y, vx, vy]
def dif(vec, t):
# time derivative of the whole vector vec
v = hypot(vec, vec)
vxrel, vyrel = vec / v, vec / v
return [vec, vec, -mu * v**pot * vxrel, -g - mu * v**pot * vyrel]

# solve the differential equation numerically
vec = odeint(dif, [xy0, xy0, vxy0, vxy0], tt)
return vec[:, 0], vec[:, 1], vec[:, 2], vec[:, 3]  # return x, y, vx, vy

g = 1.
v0 = sqrt(g/sin(2*theta))
vinf = 2.1
# use identical terminal velocity vinf for both types of friction
mu_stokes = g / vinf**1
mu_newton = g / vinf**2
x0, y0 = 0.0, 0.0
vx0, vy0 = v0 * cos(theta), v0 * sin(theta)

T = newton(lambda t: projectile_motion(g, 0, 0, (x0, y0), (vx0, vy0), [0, t]), 2*vy0/g)
nsub = 10
tt = np.linspace(0, T * nframes / (nframes - 1), (nframes - 1) * nsub + 1)

traj_free = projectile_motion(g, 0, 0, (x0, y0), (vx0, vy0), tt)
traj_stokes = projectile_motion(g, mu_stokes, 1, (x0, y0), (vx0, vy0), tt)
traj_newton = projectile_motion(g, mu_newton, 2, (x0, y0), (vx0, vy0), tt)

def animate(nframe, saveframes=False):
print(nframe, '/', nframes)
t = T * float(nframe) / nframes

plt.clf()
fig.gca().set_position((l, b, w, h))
fig.gca().set_aspect("equal")
plt.xlim(0, 1)
plt.ylim(0, (h*size) / (w*size))
plt.xticks([]), plt.yticks([])
plt.xlabel('Distance', size=12)
plt.ylabel('Height', size=12)

plt.plot(traj_free[:nframe*nsub+1], traj_free[:nframe*nsub+1],
'-', lw=lw, color=c1)
plt.plot(traj_free[nframe*nsub], traj_free[nframe*nsub],
'ok', color=c1, markersize=ms, markeredgewidth=0)

plt.plot(traj_stokes[:nframe*nsub+1], traj_stokes[:nframe*nsub+1],
'-', lw=lw, color=c2)
plt.plot(traj_stokes[nframe*nsub], traj_stokes[nframe*nsub],
'ok', color=c2, markersize=ms, markeredgewidth=0)

plt.plot(traj_newton[:nframe*nsub+1], traj_newton[:nframe*nsub+1],
'-', lw=lw, color=c3)
plt.plot(traj_newton[nframe*nsub], traj_newton[nframe*nsub],
'ok', color=c3, markersize=ms, markeredgewidth=0)

if saveframes:
# export frame
dig = int(ceil(log10(nframes)))
fsavename = ('frame{:0' + str(dig) + '}.svg').format(nframe)
fig.savefig(fsavename)
with open(fsavename) as f: content = f.read()
content = content.replace('pt"', 'px"').replace('pt"', 'px"')
with open(fsavename, 'w') as f: f.write(content)

fig = plt.figure(figsize=(size/72., size/72.))

os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
for i in range(nframes):
animate(i, True)
os.system('convert -loop 0 -delay ' + str(delay) + ' frame*.svg +dither ' + fname + '.gif')
# keep last frame for two seconds
os.system('gifsicle -k32 --color-method blend-diversity -b ' + fname + '.gif -d' + str(delay) + ' "#0-' + str(nframes-2) + '" -d200 "#' + str(nframes-1) + '"')
for i in os.listdir('.'):
if i.startswith('frame') and i.endswith('.svg'):
os.remove(i)
```

## Licensing

I, the copyright holder of this work, hereby publish it under the following license:   This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license. You are free: to share – to copy, distribute and transmit the work to remix – to adapt the work Under the following conditions: attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

### Captions

Add a one-line explanation of what this file represents

## File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current16:10, 21 October 2020 400 × 288 (374 KB)Geek3adjusted friction coefficients such to make terminal velocity of both trajectories equal. In this case, the Newton projectile moves further.
12:57, 21 October 2009 400 × 288 (453 KB)AllenMcC.added Newton drag
00:40, 22 December 2008 400 × 299 (393 KB)AllenMcC.== Summary == {{Information |Description={{en|1=Trajectories of two objects thrown at the same angle. The blue object doesn't experience any drag and moves along a parabola. The black object experiences Stokes' drag.}} |Source=Own work by uploader |Author
20:12, 18 December 2008 400 × 299 (393 KB)AllenMcC.== Summary == {{Information |Description={{en|1=Trajectories of two objects thrown at the same angle. The blue object doesn't experience any drag and moves along a parabola. The black object experiences Stokes' drag.}} |Source=Own work by uploader |Author
04:07, 15 December 2008 700 × 519 (636 KB)AllenMcC.{{Information |Description={{en|1=Trajectories of two objects thrown at the same angle. The blue object doesn't experience friction and moves along a parabola. The black object experiences Stokes friction.}} |Source=Own work by uploader |Author=[[User:All
The following pages on the English Wikipedia use this file (pages on other projects are not listed):

## Global file usage

The following other wikis use this file:

• Usage on af.wikipedia.org
• Usage on ar.wikipedia.org
• Usage on be.wikipedia.org
• Usage on bg.wikipedia.org
• Usage on bn.wikipedia.org
• Usage on ca.wikipedia.org
• Usage on cv.wikipedia.org
• Usage on da.wikipedia.org
• Usage on de.wikipedia.org
• Usage on el.wikipedia.org
• Usage on eo.wikipedia.org
• Usage on es.wikipedia.org
• Usage on eu.wikipedia.org
• Usage on fa.wikipedia.org
• Usage on fi.wikipedia.org
• Usage on ga.wikipedia.org
• Usage on he.wikipedia.org
• Usage on hi.wikipedia.org
• Usage on hr.wikipedia.org
• Usage on ht.wikipedia.org
• Usage on hu.wikipedia.org
• Usage on hy.wikipedia.org
• Usage on it.wikipedia.org
• Usage on it.wikibooks.org
• Usage on it.wikiversity.org
• Usage on ja.wikipedia.org
• Usage on ja.wikibooks.org
• Usage on kk.wikipedia.org
• Usage on mk.wikipedia.org
• Usage on nl.wikipedia.org
• Usage on pa.wikipedia.org
• Usage on pt.wikipedia.org
• Usage on ro.wikipedia.org

View more global usage of this file.