Advertisement
matthewrmata

PITCHf/x Movement Overhead View

Jan 25th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 6.13 KB | None | 0 0
  1. \documentclass[12pt]{article}
  2.  
  3. \usepackage[paperwidth=215pt, paperheight=215pt,margin=12pt]{geometry}
  4. \usepackage{color,tikz,ifthen,animate,pgf}
  5.  
  6. \begin{document}
  7.  
  8. % This code will simulate a pitch based on the 9-parameter PITCHf/x model, including the pitch plane and projections for PITCHf/x movement without (red) and with (blue dashed) accounted for.
  9.  
  10. % Written by Matthew Mata, January 2017.
  11.  
  12. \thispagestyle{empty}
  13.  
  14. % Set the counter
  15. \newcounter{m}
  16. \setcounter{m}{0}
  17.  
  18. % Set the PITCHf/x parameters
  19. \pgfmathsetmacro{\xo}{3.841}
  20. \pgfmathsetmacro{\yo}{50.0}
  21. \pgfmathsetmacro{\zo}{5.573}
  22. \pgfmathsetmacro{\vxo}{-17.203}
  23. \pgfmathsetmacro{\vyo}{-144.942}
  24. \pgfmathsetmacro{\vzo}{-5.017}
  25. \pgfmathsetmacro{\ax}{37.647}
  26. \pgfmathsetmacro{\ay}{49.266}
  27. \pgfmathsetmacro{\az}{-9.706}
  28.  
  29. % Set gravity
  30. \pgfmathsetmacro{\g}{-32.174}
  31.  
  32. % Find the time to home plate from 50 feet
  33. \pgfmathsetmacro{\r}{\vyo/\ay}
  34. \pgfmathsetmacro{\s}{2*(\yo-(17/12))/\ay}
  35. \pgfmathsetmacro{\tplate}{-\r - sqrt(\r*\r - \s)}
  36.  
  37. % Find the time of release at 55 feet
  38. \pgfmathsetmacro{\u}{2*(\yo-55)/\ay}
  39. \pgfmathsetmacro{\trel}{-\r - sqrt(\r*\r - \u)}
  40.  
  41. % Find the flight time of the pitch
  42. \pgfmathsetmacro{\t}{\tplate - \trel}
  43.  
  44. % Set the end velocities
  45. \pgfmathsetmacro{\vxend}{\vxo + \tplate*\ax}
  46. \pgfmathsetmacro{\vyend}{\vyo + \tplate*\ay}
  47. \pgfmathsetmacro{\vzend}{\vzo + \tplate*\az}
  48.  
  49. % Set the number of frames
  50. \pgfmathtruncatemacro{\frames}{int(round(\t*60)+1)}
  51.  
  52. % Set the time increment
  53. \pgfmathsetmacro{\dt}{\t/(\frames-1)}
  54.  
  55. \begin{center}
  56.     \begin{animateinline}[poster=first,loop,controls]{60}
  57.         \whiledo{\them < \frames}{
  58.             \begin{tikzpicture}[scale=0.725]
  59.                 \clip(-4,-1) rectangle (4,7);
  60.                 % Plot the field
  61.                 \draw[green!75!black,fill=green!75!black] (-4,7) -- (4,7) -- (4,-1) -- (-4,-1) -- cycle;
  62.                 \draw[brown!75!black,fill=brown!75!black] (0,0) circle [radius=1.3];
  63.                 \draw[brown!75!black,fill=brown!75!black] (0,6.05) circle [radius=0.9];
  64.                 \draw[white!75!brown,fill=white!75!brown] (-0.1,6.05) -- (-0.1,6.1) -- (0.1,6.1) -- (0.1,6.05) -- cycle;
  65.                 \draw[thick, white!75!brown] (0.3708,0.3708) -- (6.364,6.364);
  66.                 \draw[thick, white!75!brown] (-0.3708,0.3708) -- (-6.364,6.364);
  67.                 \draw[white, thick, fill=white] (0,0) -- (0.0708,0.0708) -- (0.0708,0.1416) -- (-0.0708,0.1416) -- (-0.0708,0.0708) -- cycle;
  68.                 \draw[white!75!brown, thick] (0.1208,0.3708) -- (0.5208,0.3708) -- (0.5208,-0.2291) -- (0.1208,-0.2291) -- cycle;
  69.                 \draw[white!75!brown, thick] (-0.1208,0.3708) -- (-0.5208,0.3708) -- (-0.5208,-0.2291) -- (-0.1208,-0.2291) -- cycle;
  70.                 \draw[white!75!brown, thick] (0.179,-0.2291) -- (0.179,-0.8) -- (-0.179,-0.8) -- (-0.179,-0.2291);
  71.                 % Calculate the time increment
  72.                 \pgfmathsetmacro{\tinc}{\dt*\them + \trel};
  73.                 % Current flight time of the pitch
  74.                 \pgfmathsetmacro{\time}{\dt*\them};
  75.                 % Find the x and y positions of the pitch
  76.                 \pgfmathsetmacro{\xraw}{0.5*\ax*\tinc*\tinc + \vxo*\tinc + \xo};
  77.                 \pgfmathsetmacro{\yraw}{0.5*\ay*\tinc*\tinc + \vyo*\tinc + \yo};
  78.                 % Velocity of the pitch at the given time
  79.                 \pgfmathsetmacro{\vx}{\ax*\tinc + \vxo};
  80.                 \pgfmathsetmacro{\vy}{\ay*\tinc + \vyo};
  81.                 \pgfmathsetmacro{\vz}{\az*\tinc + \vzo};
  82.                 \pgfmathsetmacro{\vel}{sqrt((15*\vx/22)*(15*\vx/22) + (15*\vy/22)*(15*\vy/22) + (15*\vz/22)*(15*\vz/22))};
  83.                 % Time remaining
  84.                 \pgfmathsetmacro{\trem}{\tplate-\tinc};
  85.                 % Projection of the pitch into the strike zone excluding drag
  86.                 \pgfmathsetmacro{\xproj}{\vx*(\tplate - \tinc) + \xraw};
  87.                 % Projection of the pitch into the strike zone including drag
  88.                 \pgfmathsetmacro{\vxbar}{(\vx+\vxend)/2};
  89.                 \pgfmathsetmacro{\vybar}{(\vy+\vyend)/2};
  90.                 \pgfmathsetmacro{\vzbar}{(\vz+\vzend)/2};
  91.                 \pgfmathsetmacro{\vbar}{1.25*sqrt((\vxbar/1.25)*(\vxbar/1.25) + (\vybar/1.25)*(\vybar/1.25) + (\vzbar/1.25)*(\vzbar/1.25))};
  92.                 \pgfmathsetmacro{\vcoeff}{-abs(\ax*(\vxbar/\vbar) + \ay*(\vybar/\vbar) + (\az-\g)*(\vzbar/\vbar))};
  93.                 \pgfmathsetmacro{\axdrag}{\vcoeff*(\vxbar/\vbar)};
  94.                 \pgfmathsetmacro{\aydrag}{\vcoeff*(\vybar/\vbar)};
  95.                 \pgfmathsetmacro{\azdrag}{\g + \vcoeff*(\vzbar/\vbar)};
  96.                 \pgfmathsetmacro{\xprojdrag}{0.5*\axdrag*(\tplate-\tinc)*(\tplate-\tinc) + \vx*(\tplate-\tinc) + \xraw};
  97.                 % Plot a straight line from the ball to the projection without drag
  98.                 \draw[red] ({0.1*\xraw},{0.1*\yraw}) -- ({0.1*\xproj},{0.1*(17/12)});              
  99.                 % Plot a curve from the ball to the projection with drag
  100.                 \pgfmathsetmacro{\framesadj}{\frames-1}
  101.                 \ifthenelse{ \them < \framesadj }{
  102.                 \draw[blue, domain=0:\trem, smooth, dashed] plot ({0.1*(0.5*\axdrag*\x*\x + \vx*\x + \xraw)},{0.1*(0.5*\ay*\x*\x + \vy*\x + \yraw)});
  103.                 }
  104.                 {
  105.                 }
  106.                 % Plot the projection without drag
  107.                 \draw[red, ball color=red, shading=ball] ({0.1*\xproj},{0.1*(17/12)}) circle [radius=0.025];
  108.                 % Plot the projection with drag
  109.                 \draw[blue, ball color=blue, shading=ball] ({0.1*\xprojdrag},{0.1*(17/12)}) circle [radius=0.025];
  110.                 % Plot the ball
  111.                 \draw[white, ball color=white, shading=ball] ({0.1*\xraw},{0.1*\yraw}) circle [radius=0.025];
  112.                 % Display the metrics
  113.                 \node[above right] at (-4,6) {Dist.: };
  114.                 \node[above left] at (-1.25,6) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
  115.                 \node[above right] at (-1.5,6) {ft};
  116.                 \node[above right] at (0,6) {Vel.: };
  117.                 \node[above left] at (2.75,6) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
  118.                 \node[above left] at (4,5.9) {mph};
  119.                 \node[above right] at (-4,-1) {Time: };
  120.                 \node[above left] at (-1,-1) {\pgfmathprintnumber[precision=2,fixed]{\time}};
  121.                 \node[above right] at (-1.25,-1) {sec};
  122.                 \foreach \n in {0,...,\frames}{
  123.                     \ifthenelse{\n < \them}{
  124.                         \pgfmathsetmacro{\tshadow}{\dt*\n + \trel};
  125.                         \pgfmathsetmacro{\xshadow}{0.5*\ax*\tshadow*\tshadow + \vxo*\tshadow + \xo};
  126.                         \pgfmathsetmacro{\yshadow}{0.5*\ay*\tshadow*\tshadow + \vyo*\tshadow + \yo};
  127.                         \draw[white, ball color=white, shading=ball, opacity=0.5] ({0.1*\xshadow},{0.1*\yshadow}) circle [radius=0.025];
  128.                     }
  129.                 }
  130.             \end{tikzpicture}
  131.             \stepcounter{m}
  132.             \ifthenelse{\them < \frames}{
  133.                 \newframe
  134.             }
  135.             {
  136.                 \end{animateinline} \relax
  137.             }
  138.         }
  139. \end{center}
  140.  
  141. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement