Advertisement
matthewrmata

PITCHf/x Movement Home Plate View

Jan 25th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 5.67 KB | None | 0 0
  1. \documentclass[12pt]{article}
  2.  
  3. \usepackage[paperwidth=200pt, paperheight=200pt,margin=12pt]{geometry}
  4. \usepackage{color,tikz,ifthen,animate}
  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}{1.62}
  20. \pgfmathsetmacro{\yo}{50.0}
  21. \pgfmathsetmacro{\zo}{6.19}
  22. \pgfmathsetmacro{\vxo}{-7.97}
  23. \pgfmathsetmacro{\vyo}{-123.74}
  24. \pgfmathsetmacro{\vzo}{-8.91}
  25. \pgfmathsetmacro{\ax}{36.06}
  26. \pgfmathsetmacro{\ay}{6.56}
  27. \pgfmathsetmacro{\az}{-19.27}
  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 to home plate
  42. \pgfmathsetmacro{\thp}{\tplate - \trel}
  43.  
  44. % Set time to catcher's mitt
  45. \pgfmathsetmacro{\u}{2*(\yo+4)/\ay}
  46. \pgfmathsetmacro{\tmitt}{-\r - sqrt(\r*\r - \u)}
  47.  
  48. % Set time between release and mitt
  49. \pgfmathsetmacro{\tcm}{\tmitt - \trel}
  50.  
  51. % Set the end velocities
  52. \pgfmathsetmacro{\vxend}{\vxo + \tplate*\ax}
  53. \pgfmathsetmacro{\vyend}{\vyo + \tplate*\ay}
  54. \pgfmathsetmacro{\vzend}{\vzo + \tplate*\az}
  55.  
  56. % Set the x-location of the pitch at home plate
  57. \pgfmathsetmacro{\xplate}{0.5*\ax*\tplate*\tplate + \vxo*\tplate + \xo}
  58.  
  59. % Set the number of frames
  60. \pgfmathtruncatemacro{\frames}{int(round(\tcm*60)+1)}
  61.  
  62. % Set the number of frames to the plate
  63. \pgfmathtruncatemacro{\framesplate}{int(round(\thp*60)+1)}
  64.  
  65. % Set the time increment
  66. \pgfmathsetmacro{\dt}{\tcm/(\frames-1)}
  67.  
  68. % Create the animation
  69. \begin{center}
  70.     \begin{animateinline}[poster=first,loop,controls]{60}
  71.         \whiledo{\them < \frames}{
  72.             \begin{tikzpicture}
  73.                 % Clip off anything out of frame
  74.                 \clip (-2,-2.5) rectangle (4,2.5);
  75.                 % Dirt, foul lines, catcher's box, and batter's boxes
  76.                 \draw[fill=brown!50!black] (-2,-2.5) -- (4,-2.5) -- (4,2.5) -- (-2,2.5) -- cycle;
  77.                 \draw[fill=white!80!brown] (-17/12,-17/24) -- (-17/12,17/24) -- (-8.5/12,17/24) -- (0,0) -- (-8.5/12,-17/24) -- cycle;
  78.                 \draw[ultra thick, white!80!brown] (-2,29/24) -- (3,29/24) -- (3,2.5);
  79.                 \draw[ultra thick, white!80!brown] (-2,-29/24) -- (3,-29/24) -- (3,-2.5);
  80.                 \draw[ultra thick, white!80!brown] (3,43/24) -- (4,43/24);
  81.                 \draw[ultra thick, white!80!brown] (3,-43/24) -- (4,-43/24);
  82.                 % Time increment between pitches
  83.                 \pgfmathsetmacro{\tinc}{\dt*\them + \trel};
  84.                 % Location of the pitch at the given time
  85.                 \pgfmathsetmacro{\xraw}{0.5*\ax*\tinc*\tinc + \vxo*\tinc + \xo};
  86.                 \pgfmathsetmacro{\yraw}{0.5*\ay*\tinc*\tinc + \vyo*\tinc + \yo};
  87.                 \pgfmathsetmacro{\zraw}{0.5*\az*\tinc*\tinc + \vzo*\tinc + \zo};
  88.                 % Velocity of the pitch at the given time
  89.                 \pgfmathsetmacro{\vx}{\ax*\tinc + \vxo};
  90.                 \pgfmathsetmacro{\vy}{\ay*\tinc + \vyo};
  91.                 \pgfmathsetmacro{\vz}{\az*\tinc + \vzo};
  92.                 \pgfmathsetmacro{\vel}{sqrt((15*\vx/22)*(15*\vx/22) + (15*\vy/22)*(15*\vy/22) + (15*\vz/22)*(15*\vz/22))};
  93.                 % Projection of the pitch into the strike zone excluding drag
  94.                 \pgfmathsetmacro{\xproj}{\vx*(\tplate - \tinc) + \xraw};
  95.                 % Projection of the pitch into the strike zone including 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.                 % Projection of the pitch to the catcher's mitt
  106.                 \pgfmathsetmacro{\xmitt}{\vx*(\tmitt - \tinc) + \xraw};
  107.                 \ifthenelse{\them < \framesplate}{
  108.                     % Plot the projection without drag
  109.                     \draw[red] ({(-17/12)},\xproj) circle [radius=0.125];
  110.                     % Plot the projection with drag
  111.                     \draw[blue,dashed] ({(-17/12)},\xprojdrag) circle [radius=0.125];
  112.                 }
  113.                 {
  114.                     \draw[red] ({(-17/12)},\xplate) circle [radius=0.125];
  115.                     \draw[blue,dashed] ({(-17/12)},\xplate) circle [radius=0.125];
  116.                 }
  117.                 % Plot the ball
  118.                 \draw[white, ball color=white, shading=ball] ({-\yraw},\xraw) circle [radius=0.125];
  119.                 % Plot the pitch path
  120.                 \draw[domain={\trel-0.25}:\tinc,smooth,variable=\x,green] plot ({-0.5*\ay*\x*\x - \vyo*\x - \yo},{0.5*\ax*\x*\x + \vxo*\x + \xo});
  121.                 \draw[shading = ball, ball color = white] (-\yraw,\xraw) circle [radius=0.125];
  122.                 % Catcher's mitt
  123.                 \draw[brown!25!black, fill=brown!25!black] (4,\xmitt) ellipse (0.25 and 0.417);
  124.                 % Display the metrics
  125.                 \node[above right] at (-2,1.9) {Dist.: };
  126.                 \node[below left] at (0.1,2.47) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
  127.                 \node[above right] at (-0.15,1.9) {ft};
  128.                 \node[above right] at (-2,-2.5) {Vel.: };
  129.                 \node[above left] at (0.1,-2.5) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
  130.                 \node[below right] at (-0.1,-1.925) {mph};
  131.             \end{tikzpicture}
  132.             \stepcounter{m}
  133.             \ifthenelse{\them < \frames}{
  134.                 \newframe
  135.             }
  136.             {
  137.                 \end{animateinline} \relax
  138.             }
  139.         }
  140. \end{center}
  141.  
  142. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement