Advertisement
matthewrmata

In-Plane Movement Home Plate View

Jan 25th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 7.95 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 9 PITCHf/x parameters
  19. \pgfmathsetmacro{\xo}{1.958}
  20. \pgfmathsetmacro{\yo}{50.0}
  21. \pgfmathsetmacro{\zo}{6.041}
  22. \pgfmathsetmacro{\vxo}{-0.469}
  23. \pgfmathsetmacro{\vyo}{-115.739}
  24. \pgfmathsetmacro{\vzo}{-0.622}
  25. \pgfmathsetmacro{\ax}{-10.947}
  26. \pgfmathsetmacro{\ay}{23.455}
  27. \pgfmathsetmacro{\az}{-32.665}
  28.  
  29. % Set gravity
  30. \pgfmathsetmacro{\g}{-32.174}
  31.  
  32. % Set the binormal vector
  33. \pgfmathsetmacro{\Bx}{\vyo*\az - \vzo*\ay}
  34. \pgfmathsetmacro{\By}{\vzo*\ax - \vxo*\az}
  35. \pgfmathsetmacro{\Bz}{\vxo*\ay - \vyo*\ax}
  36. \pgfmathsetmacro{\Bnorm}{100*sqrt((0.01*\Bx)*(0.01*\Bx) + (0.01*\By)*(0.01*\By) + (0.01*\Bz)*(0.01*\Bz))}
  37. \pgfmathsetmacro{\Bx}{\Bx/\Bnorm}
  38. \pgfmathsetmacro{\By}{\By/\Bnorm}
  39. \pgfmathsetmacro{\Bz}{\Bz/\Bnorm}
  40.  
  41. % Find the fixed B-coordinate
  42. \pgfmathsetmacro{\Bfixed}{\Bx*\xo + \By*\yo + \Bz*\zo}
  43.  
  44. % Set the vector in the direction of home plate, u
  45. \pgfmathsetmacro{\Ux}{(\Bx/abs(\Bx))*(-\By)/sqrt(\Bx*\Bx + \By*\By)}
  46. \pgfmathsetmacro{\Uy}{abs(\Bx)/sqrt(\Bx*\Bx + \By*\By)}
  47. \pgfmathsetmacro{\Uz}{0}
  48.  
  49. % Set the vector in the direction of movement, w
  50. \pgfmathsetmacro{\signW}{(\Bx*\Uy-\By*\Ux)/abs(\Bx*\Uy-\By*\Ux)}
  51. \pgfmathsetmacro{\Wx}{\signW*(-\Bz*\Uy)}
  52. \pgfmathsetmacro{\Wy}{\signW*(\Bz*\Ux)}
  53. \pgfmathsetmacro{\Wz}{\signW*(\Bx*\Uy-\By*\Ux)}
  54. \pgfmathsetmacro{\Wnorm}{sqrt(\Wx*\Wx + \Wy*\Wy + \Wz*\Wz)}
  55. \pgfmathsetmacro{\Wx}{\Wx/\Wnorm}
  56. \pgfmathsetmacro{\Wy}{\Wy/\Wnorm}
  57. \pgfmathsetmacro{\Wz}{\Wz/\Wnorm}
  58.  
  59. % Find the position, velocity, and acceleration in uw-space
  60. \pgfmathsetmacro{\uo}{\Ux*\xo + \Uy*\yo + \Uz*\zo}
  61. \pgfmathsetmacro{\vuo}{\Ux*\vxo + \Uy*\vyo + \Uz*\vzo}
  62. \pgfmathsetmacro{\au}{\Ux*\ax + \Uy*\ay + \Uz*\az}
  63. \pgfmathsetmacro{\wo}{\Wx*\xo + \Wy*\yo + \Wz*\zo}
  64. \pgfmathsetmacro{\vwo}{\Wx*\vxo + \Wy*\vyo + \Wz*\vzo}
  65. \pgfmathsetmacro{\aw}{\Wx*\ax + \Wy*\ay + \Wz*\az}
  66. \pgfmathsetmacro{\gw}{\Wz*\g}
  67.  
  68. % Find the time to home plate from 50 feet
  69. \pgfmathsetmacro{\r}{\vyo/\ay}
  70. \pgfmathsetmacro{\s}{2*(\yo-(17/12))/\ay}
  71. \pgfmathsetmacro{\tplate}{-\r - sqrt(\r*\r - \s)}
  72.  
  73. % Find the time of release at 55 feet
  74. \pgfmathsetmacro{\u}{2*(\yo-55)/\ay}
  75. \pgfmathsetmacro{\trel}{-\r - sqrt(\r*\r - \u)}
  76.  
  77. % Find the flight time of the pitch to home plate
  78. \pgfmathsetmacro{\thp}{\tplate - \trel}
  79.  
  80. % Set time to catcher's mitt
  81. \pgfmathsetmacro{\u}{2*(\yo+4)/\ay}
  82. \pgfmathsetmacro{\tmitt}{-\r - sqrt(\r*\r - \u)}
  83.  
  84. % Set time between release and mitt
  85. \pgfmathsetmacro{\tcm}{\tmitt - \trel}
  86.  
  87. % Set the end velocities
  88. \pgfmathsetmacro{\vxend}{\vxo + \tplate*\ax}
  89. \pgfmathsetmacro{\vyend}{\vyo + \tplate*\ay}
  90. \pgfmathsetmacro{\vzend}{\vzo + \tplate*\az}
  91.  
  92. % Set the x-location of the pitch at home plate
  93. \pgfmathsetmacro{\xplate}{0.5*\ax*\tplate*\tplate + \vxo*\tplate + \xo}
  94.  
  95. % Set the number of frames
  96. \pgfmathtruncatemacro{\frames}{int(round(\tcm*60)+1)}
  97.  
  98. % Set the number of frames to the plate
  99. \pgfmathtruncatemacro{\framesplate}{int(round(\thp*60)+1)}
  100.  
  101. % Set the time increment
  102. \pgfmathsetmacro{\dt}{\tcm/(\frames-1)}
  103.  
  104. % Create the animation
  105. \begin{center}
  106.     \begin{animateinline}[poster=first,loop,controls]{60}
  107.         \whiledo{\them < \frames}{
  108.             \begin{tikzpicture}
  109.                 % Clip off anything out of frame
  110.                 \clip (-2,-2.5) rectangle (4,2.5);
  111.                 % Dirt, foul lines, catcher's box, and batter's boxes
  112.                 \draw[fill=brown!50!black] (-2,-2.5) -- (4,-2.5) -- (4,2.5) -- (-2,2.5) -- cycle;
  113.                 \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;
  114.                 \draw[ultra thick, white!80!brown] (-2,29/24) -- (3,29/24) -- (3,2.5);
  115.                 \draw[ultra thick, white!80!brown] (-2,-29/24) -- (3,-29/24) -- (3,-2.5);
  116.                 \draw[ultra thick, white!80!brown] (3,43/24) -- (4,43/24);
  117.                 \draw[ultra thick, white!80!brown] (3,-43/24) -- (4,-43/24);
  118.                 % Time increment between pitches
  119.                 \pgfmathsetmacro{\tinc}{\dt*\them + \trel};
  120.                 % Location of the pitch at the given time
  121.                 \pgfmathsetmacro{\xraw}{0.5*\ax*\tinc*\tinc + \vxo*\tinc + \xo};
  122.                 \pgfmathsetmacro{\yraw}{0.5*\ay*\tinc*\tinc + \vyo*\tinc + \yo};
  123.                 \pgfmathsetmacro{\zraw}{0.5*\az*\tinc*\tinc + \vzo*\tinc + \zo};
  124.                 % Velocity of the pitch at the given time
  125.                 \pgfmathsetmacro{\vx}{\ax*\tinc + \vxo};
  126.                 \pgfmathsetmacro{\vy}{\ay*\tinc + \vyo};
  127.                 \pgfmathsetmacro{\vz}{\az*\tinc + \vzo};
  128.                 \pgfmathsetmacro{\vel}{sqrt((15*\vx/22)*(15*\vx/22) + (15*\vy/22)*(15*\vy/22) + (15*\vz/22)*(15*\vz/22))};
  129.                 % Projection of the in-plane pitch excluding drag
  130.                 \pgfmathsetmacro{\uraw}{0.5*\au*\tinc*\tinc + \vuo*\tinc + \uo};
  131.                 \pgfmathsetmacro{\wraw}{0.5*\aw*\tinc*\tinc + \vwo*\tinc + \wo};
  132.                 \pgfmathsetmacro{\vu}{\au*\tinc + \vuo};
  133.                 \pgfmathsetmacro{\vw}{\aw*\tinc + \vwo};
  134.                 \pgfmathsetmacro{\uproj}{0.5*\au*(\tplate - \tinc)*(\tplate - \tinc) + \vu*(\tplate - \tinc) + \uraw};
  135.                 \pgfmathsetmacro{\wproj}{0.5*\gw*(\tplate - \tinc)*(\tplate - \tinc) + \vw*(\tplate - \tinc) + \wraw};
  136.                 \pgfmathsetmacro{\xplane}{\Ux*\uproj + \Wx*\wproj + \Bx*\Bfixed};
  137.                 % Calculate the drag
  138.                 \pgfmathsetmacro{\vxbar}{(\vx+\vxend)/2};
  139.                 \pgfmathsetmacro{\vybar}{(\vy+\vyend)/2};
  140.                 \pgfmathsetmacro{\vzbar}{(\vz+\vzend)/2};
  141.                 \pgfmathsetmacro{\vbar}{1.25*sqrt((\vxbar/1.25)*(\vxbar/1.25) + (\vybar/1.25)*(\vybar/1.25) + (\vzbar/1.25)*(\vzbar/1.25))};
  142.                 \pgfmathsetmacro{\vcoeff}{-abs(\ax*(\vxbar/\vbar) + \ay*(\vybar/\vbar) + (\az-\g)*(\vzbar/\vbar))};
  143.                 \pgfmathsetmacro{\axdrag}{\vcoeff*(\vxbar/\vbar)};
  144.                 \pgfmathsetmacro{\aydrag}{\vcoeff*(\vybar/\vbar)};
  145.                 \pgfmathsetmacro{\azdrag}{\g + \vcoeff*(\vzbar/\vbar)};
  146.                 % Contribution of drag in the w-direction
  147.                 \pgfmathsetmacro{\awdrag}{\Wx*\axdrag + \Wy*\aydrag + \Wz*\azdrag};
  148.                 % Projection of the in-plane pitch into the strike zone including drag
  149.                 \pgfmathsetmacro{\wprojdrag}{0.5*\awdrag*(\tplate - \tinc)*(\tplate - \tinc) + \vw*(\tplate - \tinc) + \wraw};
  150.                 \pgfmathsetmacro{\xplanedrag}{\Ux*\uproj + \Wx*\wprojdrag + \Bx*\Bfixed};
  151.                 % Projection of the pitch to the catcher's mitt
  152.                 \pgfmathsetmacro{\xmitt}{\Ux*(0.5*\au*(\tmitt - \tinc)*(\tmitt - \tinc) + \vu*(\tmitt - \tinc) + \uraw) + \Wx*(0.5*\gw*(\tmitt - \tinc)*(\tmitt - \tinc) + \vw*(\tmitt - \tinc) + \wraw) + \Bx*\Bfixed};
  153.                 \ifthenelse{\them < \framesplate}{
  154.                     % Plot the projection without drag
  155.                     \draw[red] ({(-17/12)},\xplane) circle [radius=0.125];
  156.                     % Plot the projection with drag
  157.                     \draw[blue,dashed] ({(-17/12)},\xplanedrag) circle [radius=0.125];
  158.                 }
  159.                 {
  160.                     \draw[red] ({(-17/12)},\xplate) circle [radius=0.125];
  161.                     \draw[blue,dashed] ({(-17/12)},\xplate) circle [radius=0.125];
  162.                 }
  163.                 % Plot the ball
  164.                 \draw[white, ball color=white, shading=ball] ({-\yraw},\xraw) circle [radius=0.125];
  165.                 % Plot the pitch path
  166.                 \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});
  167.                 \draw[shading = ball, ball color = white] (-\yraw,\xraw) circle [radius=0.125];
  168.                 % Catcher's mitt
  169.                 \draw[brown!25!black, fill=brown!25!black] (4,\xmitt) ellipse (0.25 and 0.417);
  170.                 % Display the metrics
  171.                 \node[above right] at (-2,1.9) {Dist.: };
  172.                 \node[below left] at (0.1,2.47) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
  173.                 \node[above right] at (-0.15,1.9) {ft};
  174.                 \node[above right] at (-2,-2.5) {Vel.: };
  175.                 \node[above left] at (0.1,-2.5) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
  176.                 \node[below right] at (-0.1,-1.925) {mph};
  177.             \end{tikzpicture}
  178.             \stepcounter{m}
  179.             \ifthenelse{\them < \frames}{
  180.                 \newframe
  181.             }
  182.             {
  183.                 \end{animateinline} \relax
  184.             }
  185.         }
  186. \end{center}
  187.  
  188. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement