Advertisement
matthewrmata

In-Plane Movement Catcher View

Jan 25th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 10.87 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}{1.254}
  20. \pgfmathsetmacro{\yo}{50.0}
  21. \pgfmathsetmacro{\zo}{6.101}
  22. \pgfmathsetmacro{\vxo}{-1.23}
  23. \pgfmathsetmacro{\vyo}{-137.906}
  24. \pgfmathsetmacro{\vzo}{-9.567}
  25. \pgfmathsetmacro{\ax}{0.155}
  26. \pgfmathsetmacro{\ay}{35.877}
  27. \pgfmathsetmacro{\az}{1.229}
  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. % Set the slope and intercept of the plane's intersection with the front of the strike zone
  69. \pgfmathsetmacro{\slope}{-\Bx/\Bz}
  70. \pgfmathsetmacro{\intercept}{\zo + (\Bx/\Bz)*\xo + (\By/\Bz)*(\yo - (17/12))}
  71.  
  72. % Find the points of intersection with the ground and 5 feet vertically at the front of the strike zone
  73. \pgfmathsetmacro{\topzone}{(5 - \intercept)/\slope}
  74. \pgfmathsetmacro{\bottomzone}{-\intercept/\slope}
  75.  
  76. % Find the position of the plane at 55 feet
  77. \pgfmathsetmacro{\toprelease}{\xo + (\By/\Bx)*(\yo - 55) + (\Bz/\Bx)*(\zo-5)}
  78. \pgfmathsetmacro{\bottomrelease}{\xo + (\By/\Bx)*(\yo - 55) + (\Bz/\Bx)*\zo}
  79.  
  80. % Find the scaled location of the top/back of the plane
  81. \pgfmathsetmacro{\xdistTB}{\toprelease}
  82. \pgfmathsetmacro{\ydistTB}{55 + (73/12)}
  83. \pgfmathsetmacro{\zdistTB}{5 - 2.5}
  84. \pgfmathsetmacro{\radTB}{sqrt(\xdistTB*\xdistTB + \ydistTB*\ydistTB + \zdistTB*\zdistTB)}
  85. \pgfmathsetmacro{\thetaTB}{atan2(\ydistTB,\xdistTB)}
  86. \pgfmathsetmacro{\phiTB}{acos(\zdistTB/\radTB)}
  87. \pgfmathsetmacro{\radscaleTB}{7.5/(sin(\thetaTB)*sin(\phiTB))}
  88. \pgfmathsetmacro{\xTB}{\radscaleTB*cos(\thetaTB)*sin(\phiTB)}
  89. \pgfmathsetmacro{\zTB}{\radscaleTB*cos(\phiTB) + 2.5}
  90.  
  91. % Find the scaled location of the bottom/back of the plane
  92. \pgfmathsetmacro{\xdistBB}{\bottomrelease}
  93. \pgfmathsetmacro{\ydistBB}{55 + (73/12)}
  94. \pgfmathsetmacro{\zdistBB}{0 - 2.5}
  95. \pgfmathsetmacro{\radBB}{sqrt(\xdistBB*\xdistBB + \ydistBB*\ydistBB + \zdistBB*\zdistBB)}
  96. \pgfmathsetmacro{\thetaBB}{atan2(\ydistBB,\xdistBB)}
  97. \pgfmathsetmacro{\phiBB}{acos(\zdistBB/\radBB)}
  98. \pgfmathsetmacro{\radscaleBB}{7.5/(sin(\thetaBB)*sin(\phiBB))}
  99. \pgfmathsetmacro{\xBB}{\radscaleBB*cos(\thetaBB)*sin(\phiBB)}
  100. \pgfmathsetmacro{\zBB}{\radscaleBB*cos(\phiBB) + 2.5}
  101.  
  102. % Set the time to the plate
  103. \pgfmathsetmacro{\r}{\vyo/\ay}
  104. \pgfmathsetmacro{\s}{2*(\yo-(17/12))/\ay}
  105. \pgfmathsetmacro{\tplate}{-\r - sqrt(\r*\r - \s)}
  106.  
  107. % Set time of release
  108. \pgfmathsetmacro{\u}{2*(\yo-55)/\ay}
  109. \pgfmathsetmacro{\trel}{-\r - sqrt(\r*\r - \u)}
  110.  
  111. % Set time from release to plate
  112. \pgfmathsetmacro{\t}{\tplate - \trel}
  113.  
  114. % Set the end velocities
  115. \pgfmathsetmacro{\vxend}{\vxo + \tplate*\ax}
  116. \pgfmathsetmacro{\vyend}{\vyo + \tplate*\ay}
  117. \pgfmathsetmacro{\vzend}{\vzo + \tplate*\az}
  118.  
  119. % Set the number of frames
  120. \pgfmathtruncatemacro{\frames}{int(round(\t*60)+1)}
  121.  
  122. % Set the time increment
  123. \pgfmathsetmacro{\dt}{\t/(\frames-1)}
  124.  
  125. % Create the animation
  126. \begin{center}
  127.     \begin{animateinline}[poster=first,loop,controls]{60}
  128.         \whiledo{\them < \frames}{
  129.             \begin{tikzpicture}
  130.                 % Clip off anything out of frame
  131.                 \clip (-3,0) rectangle (3,5);
  132.                 % Sky
  133.                 \shade[top color = blue!75!white, bottom color = blue!25!white] (-3,5) -- (3,5) -- (3,2.5) -- (-3,2.5) -- cycle;
  134.                 % Grass
  135.                 \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);
  136.                 % Batter's Eye
  137.                 \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;
  138.                 % Bleachers
  139.                 \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;
  140.                 \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;
  141.                 % Outfield Wall
  142.                 \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);
  143.                 % Yellow Line
  144.                 \draw[yellow] (-3,2.659) to [out=-1, in=180] (0,2.639) to [out=0, in=181] (3,2.659);
  145.                 % Mound
  146.                 \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);
  147.                 % Pitching Rubber
  148.                 \draw [white] (-0.113,2.312) -- (0.113,2.312);
  149.                          % Plot the pitch plane
  150.                 \draw[yellow!80!white] (\topzone,5) -- (\bottomzone,0) -- (\xBB,\zBB) -- (\xTB,\zTB) -- cycle;
  151.                 \fill[yellow!80!white, opacity=0.5] (\topzone,5) -- (\bottomzone,0) -- (\xBB,\zBB) -- (\xTB,\zTB) -- cycle;
  152.                 \draw[yellow, fill=yellow] (\topzone,5) circle [radius=0.04];
  153.                 \draw[yellow, fill=yellow] (\bottomzone,0) circle [radius=0.04];
  154.                 \draw[yellow, fill=yellow] (\xBB,\zBB) circle [radius=0.02];
  155.                 \draw[yellow, fill=yellow] (\xTB,\zTB) circle [radius=0.02];
  156.                 % Time increment between pitches
  157.                 \pgfmathsetmacro{\tinc}{\dt*\them + \trel};
  158.                 % Current flight time of the pitch
  159.                 \pgfmathsetmacro{\time}{\dt*\them};
  160.                 % Location of the pitch at the given time
  161.                 \pgfmathsetmacro{\xraw}{0.5*\ax*\tinc*\tinc + \vxo*\tinc + \xo};
  162.                 \pgfmathsetmacro{\yraw}{0.5*\ay*\tinc*\tinc + \vyo*\tinc + \yo};
  163.                 \pgfmathsetmacro{\zraw}{0.5*\az*\tinc*\tinc + \vzo*\tinc + \zo};
  164.                 % Velocity of the pitch at the given time
  165.                 \pgfmathsetmacro{\vx}{\ax*\tinc + \vxo};
  166.                 \pgfmathsetmacro{\vy}{\ay*\tinc + \vyo};
  167.                 \pgfmathsetmacro{\vz}{\az*\tinc + \vzo};
  168.                 \pgfmathsetmacro{\vel}{sqrt((15*\vx/22)*(15*\vx/22) + (15*\vy/22)*(15*\vy/22) + (15*\vz/22)*(15*\vz/22))};
  169.                 % Projection of the in-plane pitch excluding drag
  170.                 \pgfmathsetmacro{\uraw}{0.5*\au*\tinc*\tinc + \vuo*\tinc + \uo};
  171.                 \pgfmathsetmacro{\wraw}{0.5*\aw*\tinc*\tinc + \vwo*\tinc + \wo};
  172.                 \pgfmathsetmacro{\vu}{\au*\tinc + \vuo};
  173.                 \pgfmathsetmacro{\vw}{\aw*\tinc + \vwo};
  174.                 \pgfmathsetmacro{\uproj}{0.5*\au*(\tplate - \tinc)*(\tplate - \tinc) + \vu*(\tplate - \tinc) + \uraw};
  175.                 \pgfmathsetmacro{\wproj}{0.5*\gw*(\tplate - \tinc)*(\tplate - \tinc) + \vw*(\tplate - \tinc) + \wraw};
  176.                 \pgfmathsetmacro{\xplane}{\Ux*\uproj + \Wx*\wproj + \Bx*\Bfixed};
  177.                 \pgfmathsetmacro{\zplane}{\Uz*\uproj + \Wz*\wproj + \Bz*\Bfixed};
  178.                 % Calculate the drag
  179.                 \pgfmathsetmacro{\vxbar}{(\vx+\vxend)/2};
  180.                 \pgfmathsetmacro{\vybar}{(\vy+\vyend)/2};
  181.                 \pgfmathsetmacro{\vzbar}{(\vz+\vzend)/2};
  182.                 \pgfmathsetmacro{\vbar}{1.25*sqrt((\vxbar/1.25)*(\vxbar/1.25) + (\vybar/1.25)*(\vybar/1.25) + (\vzbar/1.25)*(\vzbar/1.25))};
  183.                 \pgfmathsetmacro{\vcoeff}{-abs(\ax*(\vxbar/\vbar) + \ay*(\vybar/\vbar) + (\az-\g)*(\vzbar/\vbar))};
  184.                 \pgfmathsetmacro{\axdrag}{\vcoeff*(\vxbar/\vbar)};
  185.                 \pgfmathsetmacro{\aydrag}{\vcoeff*(\vybar/\vbar)};
  186.                 \pgfmathsetmacro{\azdrag}{\g + \vcoeff*(\vzbar/\vbar)};
  187.                 % Contribution of drag in the w-direction
  188.                 \pgfmathsetmacro{\awdrag}{\Wx*\axdrag + \Wy*\aydrag + \Wz*\azdrag};
  189.                 % Projection of the in-plane pitch into the strike zone including drag
  190.                 \pgfmathsetmacro{\wprojdrag}{0.5*\awdrag*(\tplate - \tinc)*(\tplate - \tinc) + \vw*(\tplate - \tinc) + \wraw};
  191.                 \pgfmathsetmacro{\xplanedrag}{\Ux*\uproj + \Wx*\wprojdrag + \Bx*\Bfixed};
  192.                 \pgfmathsetmacro{\zplanedrag}{\Uz*\uproj + \Wz*\wprojdrag + \Bz*\Bfixed};
  193.                 % Distance to the catcher's viewpoint
  194.                 \pgfmathsetmacro{\xdist}{\xraw};
  195.                 \pgfmathsetmacro{\ydist}{\yraw + (73/12)};
  196.                 \pgfmathsetmacro{\zdist}{\zraw - 2.5};
  197.                 % Spherical coordinates of the pitch
  198.                 \pgfmathsetmacro{\rad}{sqrt(\xdist*\xdist + \ydist*\ydist + \zdist*\zdist)};
  199.                 \pgfmathsetmacro{\theta}{atan2(\ydist,\xdist)};
  200.                 \pgfmathsetmacro{\phi}{acos(\zdist/\rad)};
  201.                 \pgfmathsetmacro{\radscale}{7.5/(sin(\theta)*sin(\phi))};
  202.                 % Location of the pitch from the catcher's perspective
  203.                 \pgfmathsetmacro{\xscale}{\radscale*cos(\theta)*sin(\phi)};
  204.                 \pgfmathsetmacro{\zscale}{\radscale*cos(\phi) + 2.5};
  205.                 \pgfmathsetmacro{\rscale}{(7.5*0.125)/\rad};
  206.                 % Plot the pitch
  207.                 \draw[shading = ball, ball color = white] (\xscale,\zscale) circle [radius=\rscale];
  208.                 % Plot the strike zone
  209.                 \draw[black!85!white] (-17/24,1.5) -- (17/24,1.5) -- (17/24,3.5) -- (-17/24,3.5) -- cycle;
  210.                 % Plot both projections
  211.                 \draw[red!80!white] (\xplane,\zplane) circle [radius=0.125];
  212.                 \draw[blue!80!white,dashed] (\xplanedrag,\zplanedrag) circle [radius=0.125];
  213.                 % Display the metrics
  214.                 \node[above right] at (-3,4.4) {Dist.: };
  215.                 \node[above left] at (-1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
  216.                 \node[above right] at (-1.2,4.4) {ft};
  217.                 \node[above right] at (0,4.4) {Vel.: };
  218.                 \node[above left] at (2.1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
  219.                 \node[above left] at (3,4.325) {mph};
  220.                 \node[above right] at (-3,0) {Time: };
  221.                 \node[above left] at (-0.9,0) {\pgfmathprintnumber[precision=2,fixed]{\time}};
  222.                 \node[above right] at (-1.1,0) {sec};
  223.             \end{tikzpicture}
  224.             \stepcounter{m}
  225.             \ifthenelse{\them < \frames}{
  226.                 \newframe
  227.             }
  228.             {
  229.                 \end{animateinline} \relax
  230.             }
  231.         }
  232. \end{center}
  233.  
  234. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement