<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/function-to-simulate-parabolic-shot-with-drag/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://feedproxy.google.com/~r/DataRValue/~3/NC1jMwZoRMQ/function-to-simulate-parabolic-shot.html"> Data R Value</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><span>Script to calculate the most important quantitative information of the drag parabolic shot in International System of Units.</span><br><span><span lang="en"><span>If you want to use another system of units you can do it by making some simple changes.</span></span></span></p>
<p><span><span lang="en"><span>This is a first approach to the problem and is totally perfectible.</span></span></span></p>
<p><span><span lang="en"><span><span lang="en"><span>To calculate the maximum range, a transcendental equation is solved regularly, but here we did a first run with a number of time values left over to approximate the time index for which the vertical position becomes zero.</span></span> </span></span></span></p>
<p><span>Inputs of the function are:<br>a) initial velocity vo (scalar) [m/s]<br>b) shot angle alfa [degrees]<br>c) (drag coefficient / mass) = b [m^-1]
<p>Parameter<br>g) gravity acceleration g = 9.81 [m/s^2]</p>
<p>The outputs of the function are:<br>T_1: ascending time [s]<br>H: maximum height [m]<br>L: maximum horizontal range [m]</p>
<p>We need to calculate:<br>x: horizontal position at time t [m]<br>y: vertical position at time t [m]<br>vox: horizontal initial velocity [m/s]<br>voy: vertical initial velocity [m/s]</p>
<p><b>drag_parabolic &lt;- function(vo, alpha, b){<br>  <br>  g &lt;- 9.81<br>  an &lt;- (2*pi*alpha)/360<br>  vox &lt;- vo*cos(an)<br>  voy &lt;- vo*sin(an)<br>  T_1 &lt;- (1/b)*log(1+(b*voy/g))<br>  H &lt;- (voy/b)-((g/b^2)*log(1+(b*voy/g)))<br>  <br>  </b># first run<b><br></b><br><span><b>  t &lt;- seq(0, 25, 1/10)
<p>  x &lt;- vector()<br>  y &lt;- vector()<br>  <br>  x &lt;- (vox/b)*(1-exp(-b*t))<br>  y &lt;- ((1/b)*((g/b)+voy)*(1-exp(-b*t)))-((g/b)*t)<br>  <br>  # time index of max. range<b> </b><br><span><b>  a_T &lt;- which(y &lt; 0)[1]-1<br>  <br>  </b># second run<b><br></b></span><br><span><b>  t_t &lt;- head(t, a_T)<br>  <br>  xx &lt;- vector()<br>  yy &lt;- vector()<br>  <br>  xx &lt;- (vox/b)*(1-exp(-b*t_t))<br>  yy &lt;- ((1/b)*((g/b)+voy)*(1-exp(-b*t_t)))-((g/b)*t_t)<br>  <br>  R &lt;- round(xx[length(xx)],2)<br>  H &lt;- round(H,2)<br>  </b></span><br><span><b>  plot(xx, yy, xlab=”X”, ylab=”Y”, type = “o”, col = “blue”, axes=F)<br>  </b></span><br><span><b>  axis(1, at = seq(0,R,R/10),labels = seq(0,R,R/10), cex.axis = 0.7)<br>  axis(2, at = seq(0,H,H/10),labels = seq(0,H,H/10), cex.axis = 0.7)<br>  <br>  print(“Initial Velocity”);print(paste(vo,”m/s”))<br>  print(“Angle of Shot”);print(paste(alpha,”degrees”))<br>  print(“Ascending Time”);print(paste(T_1,”s”))<br>  print(“Maximum Height”);print(paste(H,”m”))<br>  print(“Aprox. Max. Range”);print(paste(R,”m”, “+-2%”))<br>  <br>  legend(R/3, H/2, legend = c(paste(“vo =”, vo, “m/s”),<br>                   paste(“alpha =”, alpha,”degrees”),<br>                   paste(“Ascending time”, paste(T_1,”s”)),<br>                   paste(“Maximum height”, paste(H,”m”)),<br>                   paste(“Aprox. Max. Range”, paste(R,”m”,”+-2%”))),<br>                   cex=0.7, bg = par(“bg”))<br>  </b></span><br><span><b>title(main = “Drag Parabolic Shot”, sub = “”)<br>}</b></span></p></b>
<p><span><span lang="en"><span>Let’s try the function:</span></span></span></p>
<p><span><b>drag_parabolic(50, 45, 0.5)</b></span></p>
<div><a target="_blank" rel="nofollow" href="https://i2.wp.com/2.bp.blogspot.com/-BUk-BkxQQRg/WJOzG3FNGsI/AAAAAAAACxA/1TcIOkpKfS8tzYD6A-jy-dGT-HkXx5iAQCLcB/s1600/drag.png?ssl=1"><img src="https://i2.wp.com/2.bp.blogspot.com/-BUk-BkxQQRg/WJOzG3FNGsI/AAAAAAAACxA/1TcIOkpKfS8tzYD6A-jy-dGT-HkXx5iAQCLcB/s640/drag.png?resize=456%2C291&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><b> </b><span lang="en"><span>We compare with a simple parabolic shot with the same parameters:</span></span></span></p>
<p>
<div></div>
<div><b> <a target="_blank" rel="nofollow" href="https://i2.wp.com/4.bp.blogspot.com/-sWa2tSPTrXw/WJO06qxhNdI/AAAAAAAACxY/h4X5-ca6BQoLZhAtW2_ZClJRMe6-xSqTACLcB/s1600/no_drag.png?ssl=1"><img src="https://i0.wp.com/4.bp.blogspot.com/-sWa2tSPTrXw/WJO06qxhNdI/AAAAAAAACxY/h4X5-ca6BQoLZhAtW2_ZClJRMe6-xSqTACLcB/s640/no_drag.png?resize=456%2C302&ssl=1" border="0" data-recalc-dims="1"></a></b></div>
<div></div>
<p><span><span lang="en"><span>I will be glad to receive your comments and suggestions to improve the script.</span></span></span><br><span><span lang="en"><span> </span></span><b> </b></span><br><span><span lang="en"><span>Get the script in:</span></span></span><br><span><span lang="en"><span><a target="_blank" rel="nofollow" href="https://github.com/pakinja/Data-R-Value/tree/master/Drag_Parabolic_Shot">https://github.com/pakinja/Data-R-Value</a> </span></span></span></p>
<p><img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/DataRValue/~4/NC1jMwZoRMQ"></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://feedproxy.google.com/~r/DataRValue/~3/NC1jMwZoRMQ/function-to-simulate-parabolic-shot.html"> Data R Value</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/8z20NSJj3-8"></a></div></span></span>