Advertisement
matthewrmata

PITCHf/x Movement Catcher View

Jan 25th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 6.60 KB | None | 0 0
  1. \documentclass[12pt]{article}
  2.  
  3. \usepackage[paperwidth=200pt, paperheight=200pt,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. % Set the time to the plate
  33. \pgfmathsetmacro{\r}{\vyo/\ay}
  34. \pgfmathsetmacro{\s}{2*(\yo-(17/12))/\ay}
  35. \pgfmathsetmacro{\tplate}{-\r - sqrt(\r*\r - \s)}
  36.  
  37. % Set time of release at 55 feet
  38. \pgfmathsetmacro{\u}{2*(\yo-55)/\ay}
  39. \pgfmathsetmacro{\trel}{-\r - sqrt(\r*\r - \u)}
  40.  
  41. % Set time from release to plate
  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. % Create the animation
  56. \begin{center}
  57.     \begin{animateinline}[poster=first,loop,controls]{60}
  58.         \whiledo{\them < \frames}{
  59.             \begin{tikzpicture}
  60.                 % Clip off anything out of frame
  61.                 \clip (-3,0) rectangle (3,5);
  62.                 % Sky
  63.                 \shade[top color = blue!75!white, bottom color = blue!25!white] (-3,5) -- (3,5) -- (3,2.5) -- (-3,2.5) -- cycle;
  64.                 % Grass
  65.                 \shade[top color = green!50!black, bottom color = green!70!black] (-3,0) -- (3,0) -- (3,2.447) to [out=179, in =0] (0,2.454) to [out=180, in=1] (-3,2.447) -- (-3,0);
  66.                 % Batter's Eye
  67.                 \shade[top color = green!60!black, bottom color = green!30!black] (-0.541,3.176) -- (0.541,3.176) -- (0.541,2.5) -- (-0.541,2.5) -- cycle;
  68.                 % Bleachers
  69.                 \draw[fill = black!85!white] (-3,3.274) to [out=-1, in=180] (-0.541,3.176) -- (-0.541,2.5) -- (-3,2.5) -- cycle;
  70.                 \draw[fill = black!85!white] (3,3.274) to [out=181, in=0] (0.541,3.176) -- (0.541,2.5) -- (3,2.5) -- cycle;
  71.                 % Outfield Wall
  72.                 \shade[top color = green!40!black, bottom color = green!20!black] (-3,2.447) -- (-3,2.659) to [out=-1, in=180] (0,2.639) to [out=0, in=181] (3,2.659) -- (3,2.447) to [out=179, in =0] (0,2.454) to [out=180, in=1] (-3,2.447);
  73.                 % Yellow Line
  74.                 \draw[yellow] (-3,2.659) to [out=-1, in=180] (0,2.639) to [out=0, in=181] (3,2.659);
  75.                 % Mound
  76.                 \shade[top color = brown!90!black, bottom color = brown!70!black] (-1.014,2.218) to [out=10, in=180] (0,2.312) to [out=0, in=170] (1.014,2.218) to [out=185, in=0] (0,2.174) to [out = 180, in=355] (-1.014,2.218);
  77.                 % Pitching Rubber
  78.                 \draw [white] (-0.113,2.312) -- (0.113,2.312);
  79.                 % Time increment between pitches
  80.                 \pgfmathsetmacro{\tinc}{\dt*\them + \trel};
  81.                 % Current flight time of the pitch
  82.                 \pgfmathsetmacro{\time}{\dt*\them};
  83.                 % Location of the pitch at the given time
  84.                 \pgfmathsetmacro{\xraw}{0.5*\ax*\tinc*\tinc + \vxo*\tinc + \xo};
  85.                 \pgfmathsetmacro{\yraw}{0.5*\ay*\tinc*\tinc + \vyo*\tinc + \yo};
  86.                 \pgfmathsetmacro{\zraw}{0.5*\az*\tinc*\tinc + \vzo*\tinc + \zo};
  87.                 % Velocity of the pitch at the given time
  88.                 \pgfmathsetmacro{\vx}{\ax*\tinc + \vxo};
  89.                 \pgfmathsetmacro{\vy}{\ay*\tinc + \vyo};
  90.                 \pgfmathsetmacro{\vz}{\az*\tinc + \vzo};
  91.                 \pgfmathsetmacro{\vel}{sqrt((15*\vx/22)*(15*\vx/22) + (15*\vy/22)*(15*\vy/22) + (15*\vz/22)*(15*\vz/22))};
  92.                 % Projection of the pitch to the front of home plate without drag
  93.                 \pgfmathsetmacro{\xproj}{\vx*(\tplate - \tinc) + \xraw};
  94.                 \pgfmathsetmacro{\zproj}{0.5*\g*(\tplate - \tinc)*(\tplate - \tinc) + \vz*(\tplate - \tinc) + \zraw};
  95.                 % Projection of the pitch to the front of home plate with drag
  96.                 \pgfmathsetmacro{\vxbar}{(\vx+\vxend)/2};
  97.                 \pgfmathsetmacro{\vybar}{(\vy+\vyend)/2};
  98.                 \pgfmathsetmacro{\vzbar}{(\vz+\vzend)/2};
  99.                 \pgfmathsetmacro{\vbar}{1.25*sqrt((\vxbar/1.25)*(\vxbar/1.25) + (\vybar/1.25)*(\vybar/1.25) + (\vzbar/1.25)*(\vzbar/1.25))};
  100.                 \pgfmathsetmacro{\vcoeff}{-abs(\ax*(\vxbar/\vbar) + \ay*(\vybar/\vbar) + (\az-\g)*(\vzbar/\vbar))};
  101.                 \pgfmathsetmacro{\axdrag}{\vcoeff*(\vxbar/\vbar)};
  102.                 \pgfmathsetmacro{\aydrag}{\vcoeff*(\vybar/\vbar)};
  103.                 \pgfmathsetmacro{\azdrag}{\g + \vcoeff*(\vzbar/\vbar)};
  104.                 \pgfmathsetmacro{\xprojdrag}{0.5*\axdrag*(\tplate-\tinc)*(\tplate-\tinc) + \vx*(\tplate-\tinc) + \xraw};
  105.                 \pgfmathsetmacro{\zprojdrag}{0.5*\azdrag*(\tplate-\tinc)*(\tplate-\tinc) + \vz*(\tplate-\tinc) + \zraw};
  106.                 % Distance to the catcher's viewpoint
  107.                 \pgfmathsetmacro{\xdist}{\xraw};
  108.                 \pgfmathsetmacro{\ydist}{\yraw + (73/12)};
  109.                 \pgfmathsetmacro{\zdist}{\zraw - 2.5};
  110.                 % Spherical coordinates of the pitch
  111.                 \pgfmathsetmacro{\rad}{sqrt(\xdist*\xdist + \ydist*\ydist + \zdist*\zdist)};
  112.                 \pgfmathsetmacro{\theta}{atan2(\ydist,\xdist)};
  113.                 \pgfmathsetmacro{\phi}{acos(\zdist/\rad)};
  114.                 \pgfmathsetmacro{\radscale}{7.5/(sin(\theta)*sin(\phi))};
  115.                 % Location of the pitch from the catcher's perspective
  116.                 \pgfmathsetmacro{\xscale}{\radscale*cos(\theta)*sin(\phi)};
  117.                 \pgfmathsetmacro{\zscale}{\radscale*cos(\phi) + 2.5};
  118.                 \pgfmathsetmacro{\rscale}{(7.5*0.125)/\rad};
  119.                 % Plot the pitch
  120.                 \draw[shading = ball, ball color = white] (\xscale,\zscale) circle [radius=\rscale];
  121.                 % Plot the strike zone
  122.                 \draw[black!85!white] (-17/24,1.5) -- (17/24,1.5) -- (17/24,3.5) -- (-17/24,3.5) -- cycle;
  123.                 % Plot both projections
  124.                 \draw[red!80!white] (\xproj,\zproj) circle [radius=0.125];
  125.                 \draw[blue!80!white,dashed] (\xprojdrag,\zprojdrag) circle [radius=0.125];
  126.                 % Display the metrics
  127.                 \node[above right] at (-3,4.4) {Dist.: };
  128.                 \node[above left] at (-1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
  129.                 \node[above right] at (-1.2,4.4) {ft};
  130.                 \node[above right] at (0,4.4) {Vel.: };
  131.                 \node[above left] at (2.1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
  132.                 \node[above left] at (3,4.325) {mph};
  133.                 \node[above right] at (-3,0) {Time: };
  134.                 \node[above left] at (-0.9,0) {\pgfmathprintnumber[precision=2,fixed]{\time}};
  135.                 \node[above right] at (-1.1,0) {sec};
  136.             \end{tikzpicture}
  137.             \stepcounter{m}
  138.             \ifthenelse{\them < \frames}{
  139.                 \newframe
  140.             }
  141.             {
  142.                 \end{animateinline} \relax
  143.             }
  144.         }
  145. \end{center}
  146.  
  147. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement