Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass[12pt]{article}
- \usepackage[paperwidth=200pt, paperheight=200pt,margin=12pt]{geometry}
- \usepackage{color,tikz,ifthen,animate,pgf}
- \begin{document}
- % This code will simulate a pitch based on the 9-parameter PITCHf/x model, including the pitch plane and projections for in-plane movement (yellow) and PITCHf/x movement (red).
- % Note that due to a problem with the 'animate' package and changing opacity, the first frame of the pitch plane may appear solid. To get 55 feet with a see-through plane, change the counter, m, below from 0 to -1 to start back one frame.
- % Written by Matthew Mata, July 2016.
- \thispagestyle{empty}
- % Set the counter
- \newcounter{m}
- \setcounter{m}{0}
- % Set the 9 PITCHf/x parameters
- \pgfmathsetmacro{\xo}{-2.951}
- \pgfmathsetmacro{\yo}{50.0}
- \pgfmathsetmacro{\zo}{5.397}
- \pgfmathsetmacro{\vxo}{9.649}
- \pgfmathsetmacro{\vyo}{-119.85}
- \pgfmathsetmacro{\vzo}{-2.381}
- \pgfmathsetmacro{\ax}{3.173}
- \pgfmathsetmacro{\ay}{22.075}
- \pgfmathsetmacro{\az}{-34.452}
- \pgfmathsetmacro{\g}{-32.174}
- % Set the binormal vector
- \pgfmathsetmacro{\Bx}{\vyo*\az - \vzo*\ay}
- \pgfmathsetmacro{\By}{\vzo*\ax - \vxo*\az}
- \pgfmathsetmacro{\Bz}{\vxo*\ay - \vyo*\ax}
- \pgfmathsetmacro{\Bnorm}{100*sqrt((0.01*\Bx)*(0.01*\Bx) + (0.01*\By)*(0.01*\By) + (0.01*\Bz)*(0.01*\Bz))}
- \pgfmathsetmacro{\Bx}{\Bx/\Bnorm}
- \pgfmathsetmacro{\By}{\By/\Bnorm}
- \pgfmathsetmacro{\Bz}{\Bz/\Bnorm}
- % Find the fixed B-coordinate
- \pgfmathsetmacro{\Bfixed}{\Bx*\xo + \By*\yo + \Bz*\zo}
- % Set the vector in the direction of home plate, u
- \pgfmathsetmacro{\Ux}{(\Bx/abs(\Bx))*(-\By)/sqrt(\Bx*\Bx + \By*\By)}
- \pgfmathsetmacro{\Uy}{abs(\Bx)/sqrt(\Bx*\Bx + \By*\By)}
- \pgfmathsetmacro{\Uz}{0}
- % Set the vector in the direction of movement, w
- \pgfmathsetmacro{\signW}{(\Bx*\Uy-\By*\Ux)/abs(\Bx*\Uy-\By*\Ux)}
- \pgfmathsetmacro{\Wx}{\signW*(-\Bz*\Uy)}
- \pgfmathsetmacro{\Wy}{\signW*(\Bz*\Ux)}
- \pgfmathsetmacro{\Wz}{\signW*(\Bx*\Uy-\By*\Ux)}
- \pgfmathsetmacro{\Wnorm}{sqrt(\Wx*\Wx + \Wy*\Wy + \Wz*\Wz)}
- \pgfmathsetmacro{\Wx}{\Wx/\Wnorm}
- \pgfmathsetmacro{\Wy}{\Wy/\Wnorm}
- \pgfmathsetmacro{\Wz}{\Wz/\Wnorm}
- % Find the position, velocity, and acceleration in uw-space
- \pgfmathsetmacro{\uo}{\Ux*\xo + \Uy*\yo + \Uz*\zo}
- \pgfmathsetmacro{\vuo}{\Ux*\vxo + \Uy*\vyo + \Uz*\vzo}
- \pgfmathsetmacro{\au}{\Ux*\ax + \Uy*\ay + \Uz*\az}
- \pgfmathsetmacro{\wo}{\Wx*\xo + \Wy*\yo + \Wz*\zo}
- \pgfmathsetmacro{\vwo}{\Wx*\vxo + \Wy*\vyo + \Wz*\vzo}
- \pgfmathsetmacro{\aw}{\Wx*\ax + \Wy*\ay + \Wz*\az}
- \pgfmathsetmacro{\gw}{\Wz*\g}
- % Set the slope and intercept of the plane's intersection with the front of the strike zone
- \pgfmathsetmacro{\slope}{-\Bx/\Bz}
- \pgfmathsetmacro{\intercept}{\zo + (\Bx/\Bz)*\xo + (\By/\Bz)*(\yo - (17/12))}
- % Find the points of intersection with the ground and 5 feet vertically at the front of the strike zone
- \pgfmathsetmacro{\topzone}{(5 - \intercept)/\slope}
- \pgfmathsetmacro{\bottomzone}{-\intercept/\slope}
- % Find the position of the plane at 55 feet
- \pgfmathsetmacro{\toprelease}{\xo + (\By/\Bx)*(\yo - 55) + (\Bz/\Bx)*(\zo-5)}
- \pgfmathsetmacro{\bottomrelease}{\xo + (\By/\Bx)*(\yo - 55) + (\Bz/\Bx)*\zo}
- % Find the scaled location of the top/back of the plane
- \pgfmathsetmacro{\xdistTB}{\toprelease}
- \pgfmathsetmacro{\ydistTB}{55 + (73/12)}
- \pgfmathsetmacro{\zdistTB}{5 - 2.5}
- \pgfmathsetmacro{\radTB}{sqrt(\xdistTB*\xdistTB + \ydistTB*\ydistTB + \zdistTB*\zdistTB)}
- \pgfmathsetmacro{\thetaTB}{atan2(\xdistTB,\ydistTB)}
- \pgfmathsetmacro{\phiTB}{acos(\zdistTB/\radTB)}
- \pgfmathsetmacro{\radscaleTB}{7.5/(sin(\thetaTB)*sin(\phiTB))}
- \pgfmathsetmacro{\xTB}{\radscaleTB*cos(\thetaTB)*sin(\phiTB)}
- \pgfmathsetmacro{\zTB}{\radscaleTB*cos(\phiTB) + 2.5}
- % Find the scaled location of the bottom/back of the plane
- \pgfmathsetmacro{\xdistBB}{\bottomrelease}
- \pgfmathsetmacro{\ydistBB}{55 + (73/12)}
- \pgfmathsetmacro{\zdistBB}{0 - 2.5}
- \pgfmathsetmacro{\radBB}{sqrt(\xdistBB*\xdistBB + \ydistBB*\ydistBB + \zdistBB*\zdistBB)}
- \pgfmathsetmacro{\thetaBB}{atan2(\xdistBB,\ydistBB)}
- \pgfmathsetmacro{\phiBB}{acos(\zdistBB/\radBB)}
- \pgfmathsetmacro{\radscaleBB}{7.5/(sin(\thetaBB)*sin(\phiBB))}
- \pgfmathsetmacro{\xBB}{\radscaleBB*cos(\thetaBB)*sin(\phiBB)}
- \pgfmathsetmacro{\zBB}{\radscaleBB*cos(\phiBB) + 2.5}
- % Set the time to the plate
- \pgfmathsetmacro{\r}{\vyo/\ay}
- \pgfmathsetmacro{\s}{2*(\yo-(17/12))/\ay}
- \pgfmathsetmacro{\tplate}{-\r - sqrt(\r*\r - \s)}
- % Set time of release
- \pgfmathsetmacro{\u}{2*(\yo-55)/\ay}
- \pgfmathsetmacro{\trel}{-\r - sqrt(\r*\r - \u)}
- % Set time from release to plate
- \pgfmathsetmacro{\t}{\tplate - \trel}
- % Set the number of frames
- \pgfmathtruncatemacro{\frames}{int(round(\t*60)+1)}
- % Set the time increment
- \pgfmathsetmacro{\dt}{\t/(\frames-1)}
- % Create the animation
- \begin{center}
- \begin{animateinline}[poster=first,loop,controls]{60}
- \whiledo{\them < \frames}{
- \begin{tikzpicture}
- % Clip off anything out of frame
- \clip (-3,0) rectangle (3,5);
- % Sky
- \shade[top color = black!60!white, bottom color = black!40!white] (-3,5) -- (3,5) -- (3,2.5) -- (-3,2.5) -- cycle;
- % Grass
- \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);
- % Batter's Eye
- \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;
- % Bleachers
- \draw[fill = blue!75!black] (-3,3.274) to [out=-1, in=180] (-0.541,3.176) -- (-0.541,2.5) -- (-3,2.5) -- cycle;
- \draw[fill = blue!75!black] (3,3.274) to [out=181, in=0] (0.541,3.176) -- (0.541,2.5) -- (3,2.5) -- cycle;
- % Outfield Wall
- \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);
- % Yellow Line
- \draw[yellow] (-3,2.659) to [out=-1, in=180] (0,2.639) to [out=0, in=181] (3,2.659);
- % Mound
- \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);
- % Pitching Rubber
- \draw [white] (-0.113,2.312) -- (0.113,2.312);
- % Plot the pitch plane
- \draw[yellow!80!white] (\topzone,5) -- (\bottomzone,0) -- (\xBB,\zBB) -- (\xTB,\zTB) -- cycle;
- \fill[yellow!80!white, opacity=0.5] (\topzone,5) -- (\bottomzone,0) -- (\xBB,\zBB) -- (\xTB,\zTB) -- cycle;
- \draw[yellow, fill=yellow] (\topzone,5) circle [radius=0.04];
- \draw[yellow, fill=yellow] (\bottomzone,0) circle [radius=0.04];
- \draw[yellow, fill=yellow] (\xBB,\zBB) circle [radius=0.02];
- \draw[yellow, fill=yellow] (\xTB,\zTB) circle [radius=0.02];
- % Time increment between pitches
- \pgfmathsetmacro{\tinc}{\dt*\them + \trel};
- % Current flight time of the pitch
- \pgfmathsetmacro{\time}{\dt*\them};
- % Location of the pitch at the given time
- \pgfmathsetmacro{\xraw}{0.5*\ax*\tinc*\tinc + \vxo*\tinc + \xo};
- \pgfmathsetmacro{\yraw}{0.5*\ay*\tinc*\tinc + \vyo*\tinc + \yo};
- \pgfmathsetmacro{\zraw}{0.5*\az*\tinc*\tinc + \vzo*\tinc + \zo};
- % Velocity of the pitch at the given time
- \pgfmathsetmacro{\vx}{\ax*\tinc + \vxo};
- \pgfmathsetmacro{\vy}{\ay*\tinc + \vyo};
- \pgfmathsetmacro{\vz}{\az*\tinc + \vzo};
- \pgfmathsetmacro{\vel}{sqrt((15*\vx/22)*(15*\vx/22) + (15*\vy/22)*(15*\vy/22) + (15*\vz/22)*(15*\vz/22))};
- % Projection of the pitch into the strike zone
- \pgfmathsetmacro{\xproj}{\vx*(\tplate - \tinc) + \xraw};
- \pgfmathsetmacro{\zproj}{0.5*\g*(\tplate - \tinc)*(\tplate - \tinc) + \vz*(\tplate - \tinc) + \zraw};
- % Projection of the in-plane pitch
- \pgfmathsetmacro{\uraw}{0.5*\au*\tinc*\tinc + \vuo*\tinc + \uo};
- \pgfmathsetmacro{\wraw}{0.5*\aw*\tinc*\tinc + \vwo*\tinc + \wo};
- \pgfmathsetmacro{\vu}{\au*\tinc + \vuo};
- \pgfmathsetmacro{\vw}{\aw*\tinc + \vwo};
- \pgfmathsetmacro{\uproj}{0.5*\au*(\tplate - \tinc)*(\tplate - \tinc) + \vu*(\tplate - \tinc) + \uraw};
- \pgfmathsetmacro{\wproj}{0.5*\gw*(\tplate - \tinc)*(\tplate - \tinc) + \vw*(\tplate - \tinc) + \wraw};
- \pgfmathsetmacro{\xplane}{\Ux*\uproj + \Wx*\wproj + \Bx*\Bfixed};
- \pgfmathsetmacro{\zplane}{\Uz*\uproj + \Wz*\wproj + \Bz*\Bfixed};
- % Distance to the catcher's viewpoint
- \pgfmathsetmacro{\xdist}{\xraw};
- \pgfmathsetmacro{\ydist}{\yraw + (73/12)};
- \pgfmathsetmacro{\zdist}{\zraw - 2.5};
- % Spherical coordinates of the pitch
- \pgfmathsetmacro{\rad}{sqrt(\xdist*\xdist + \ydist*\ydist + \zdist*\zdist)};
- \pgfmathsetmacro{\theta}{atan2(\xdist,\ydist)};
- \pgfmathsetmacro{\phi}{acos(\zdist/\rad)};
- \pgfmathsetmacro{\radscale}{7.5/(sin(\theta)*sin(\phi))};
- % Location of the pitch from the catcher's perspective
- \pgfmathsetmacro{\xscale}{\radscale*cos(\theta)*sin(\phi)};
- \pgfmathsetmacro{\zscale}{\radscale*cos(\phi) + 2.5};
- \pgfmathsetmacro{\rscale}{(7.5*0.125)/\rad};
- % Plot the pitch
- \draw[shading = ball, ball color = white] (\xscale,\zscale) circle [radius=\rscale];
- % Plot the strike zone
- \draw[black!85!white] (-17/24,1.5) -- (17/24,1.5) -- (17/24,3.5) -- (-17/24,3.5) -- cycle;
- % Plot both projections
- \draw[red!80!white] (\xproj,\zproj) circle [radius=0.125];
- \draw[yellow!80!white] (\xplane,\zplane) circle [radius=0.125];
- % Display the diagnostics
- \node[above right] at (-3,4.4) {Dist.: };
- \node[above left] at (-1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\yraw}};
- \node[above right] at (-1.2,4.4) {ft};
- \node[above right] at (0,4.4) {Vel.: };
- \node[above left] at (2.1,4.4) {\pgfmathprintnumber[precision=1,fixed]{\vel}};
- \node[above left] at (3,4.325) {mph};
- \node[above right] at (-3,0) {Time: };
- \node[above left] at (-0.9,0) {\pgfmathprintnumber[precision=2,fixed]{\time}};
- \node[above right] at (-1.1,0) {sec};
- \end{tikzpicture}
- \stepcounter{m}
- \ifthenelse{\them < \frames}{
- \newframe
- }
- {
- \end{animateinline} \relax
- }
- }
- \end{center}
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement