\(\(\( (*Robert\ Lee*) \)\(
\)\( (*BaseBall\ Package*) \)\(
\)\(
\)\(
\)\( (*This\ package\ is\ a\ fun\ graphic\ animation\ of\ a\ baseball\ trajectory\ which\ includes\ air\ drag\ in\ the\ equaitons\ of\ \(\(motion\)\(.\)\)\ *) \)\(
\)\(Clear["Global`*"]\)\)\)

\(\(\(baseBall[vPitch_, vBat_] := 
	
		\ \ \ \ \ \ \ \ \ \ \ \ 
	
        Module[{vx0, vz0, sol, x, z, g1, g2, g3, g4, g5, g6, g7, g8, g9, gr, 
            tmax, angle}, 
								
			\ \ \ \ \ \ \ \ \ \ \ 	
			\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 	
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*Field*) 
		\ \ \ \ \ g1 = {RGBColor[0.002,  .8, 
                0.01], 
				\ \ \ \ \ \ \ \ \ \ Polygon[{{0, 0, 
                    0}, {350, 350, 0}, {400, 100, 0}, {400, \(-100\), 
                    0}, {350, \(-350\), 
                    0}}]}; 
							\ \ \ \ \ \ 
										 (*Grandstands*) 
			\ \ \ g2 = {RGBColor[ .5, 0.2,  .8], 
              Polygon[{
				\ \ \ 	\ \ \ \ \ {350, \(-350\), 
                    10}\ \ , {400, \(-100\), 30}, {450, \(-100\), 
                    50}, {450, \(-375\), 
                    50}}], \ \ \ \ \ \ \ 
				\ \ \ \ \ \ \ \ \ \ \ Polygon[{{400, \(-100\), 30}, {400, 100, 30}, {450, 100, 50}, {450, \(-100\), 
                    50}}], \ \ 
				\ \ \ \ \ \ \ \ \ \ \ Polygon[{{400, 
                    100, 30}, {350, 350, 10}, {450, 375, 50}, {450, 100, 
                    50}}]}; 
							\ \ \ \ \ \ \ 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*Side\ of\ Grandstands*) 
				g3 = 
	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {RGBColor[1, 0, 1], 
              Polygon[{{400, 100, 0}, {400, 100, 30}, {400, \(-100\), 
                    30}, {400, \(-100\), 
                    0}}], \ \ 
					\ \ \ \ \ \ \ Polygon[{{400, 100, 
                    0}, {400, 100, 30}, {350, 350, 10}, {350, 350, 
                    0}}], \ 
				\ \ \ \ \ \ \ \ \ Polygon[{{350, 350, 
                    10}, {350, 350, 0}, {450, 375, 0}, {450, 375, 
                    50}}], \ 
				\ \ \ \ \ \ \ \ \ Polygon[{{400, \(-100\), 30}, {400, \(-100\), 0}, {350, \(-350\), 0}, {350, \(-350\), 
                    10}}]}; 
		\ \ \ \ \ g4 = \ 
			\ \ \ \ \ \ \ \ \ \ \ {RGBColor[1, 0, 
                1], \ 
				\ \ \ \ \ \ \ \ \ Polygon[{{350, \(-350\), 
                    10}, {350, \(-350\), 0}, {450, \(-375\), 
                    0}, {450, \(-375\), 
                    50}}]}; 
		\ \ 
			\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*Diamond*) \ 
				g5 = {RGBColor[0, 0, 0], 
              Line /@ {{{4, 0, 0}, {67.5, 63.5, 
                      
                      0}}, \ \ \ \ \ \ \ \ \ \ 
					\ \ \ \ \ \ \ {{67.5, 63.5, 0}, {131, 0, 0}}, \ 
						\ \ \ \ \ {{131, 0, 
                      0}, {67.5, \(-63.5\), 0}}, {{67.5, \(-63.5\), 0}, {4, 
                      0, 0}}}}; \ 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*Birds*) 
			\ \ gr = {RGBColor[
                0, 0, 0], \ 
              Polygon[{{100 + 5  i, \(-200\), 350}, {110 + 5\ i, \(-200\), 
                    350}, {105 + 5\ i, \(-200\) + 10  Sin[2\ i], 350}}], 
              Polygon[{{80 + 5  i, \(-180\), 350}, {90 + 5\ i, \(-180\), 
                    350}, {85 + 5\ i, \(-180\) + 10  Sin[2\ i], 350}}], 
              Polygon[{{80 + 5  i, \(-220\), 350}, {90 + 5\ i, \(-220\), 
                    350}, {85 + 5\ i, \(-220\) + 10  Sin[2\ i], 350}}], 
              Polygon[{{60 + 5  i, \(-160\), 350}, {70 + 5\ i, \(-160\), 
                    350}, {65 + 5\ i, \(-160\) + 10  Sin[2\ i], 350}}], 
              Polygon[{{60 + 5  i, \(-240\), 350}, {70 + 5\ i, \(-240\), 
                    350}, {65 + 5\ i, \(-240\) + 10  Sin[2\ i], 
                    350}}]}; \ \ \ \ \ \ 
			\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
		\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*Billboard*) 
	\ \ \ \ \ \ g6 = {RGBColor[0, 0, 0], \ 
              Line /@ {{{150, 220, 0}, {150, 230, 30}}, {{230, 230, 0}, {230, 
                      230, 30}}}}; 
		\ \ \ \ g7 = {RGBColor[ .6,  .6, 
                1], 
				\ \ \ \ \ \ \ \ \ Polygon[{{150, 230, 
                    30}, {230, 230, 30}, {230, 240, 80}, {150, 230, 
                    80}}]}; 
							
	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 	 (*Flags*) 
		\ \ \ g8 = 
			\ \ \ \ \ \ \ \ \ {RGBColor[0, 0, 
                0], \ \ 
				\ \ \ \ \ \ \ Line /@ {{{450, 375, 
                      50}, {450, 375, 100}}, {{450, 100, 50}, {450, 100, 
                      100}}, \ 
						\ \ {{150, 230, 80}, {150, 230, 
                      100}}, {{230, 230, 80}, {230, 230, 
                      100}}, \ \ \ 
						\ \ {{450, \(-100\), 
                      50}, {450, \(-100\), 100}}, {{450, \(-375\), 
                      50}, {450, \(-375\), 
                      100}}}}; 
		\ \ \ g9 = \ \ {{RGBColor[1, 0, 0], 
                Polygon\ [{{450, 375, 100}, {450, 375, 130}, {458, 
                      375 + 5  Sin[i\ 2], 130}, {464, 375 + 10  Sin[i\ 2], 
                      130}, {470, 375 + 15\ Sin[i\ 2], 130}, {458, 
                      375 + 5  Sin[i\ 2], 112}, {464, 375 + 10  Sin[i\ 2], 
                      121}}], \ \ 
				\ \ \ \ \ \ \ 
						\ Polygon[{{450, 100, 100}, {450, 100, 130}, {458, 100 + 5  Sin[i\ 2 - 1.5], 
                      130}, {464, 100 + 10  Sin[i\ 2 - 1.5], 130}, {470, 
                      100 + 15\ Sin[i\ 2 - 1.5], 130}, {458, 
                      100 + 5  Sin[i\ 2 - 1.5], 112}, {464, 
                      100 + 10  Sin[i\ 2 - 1.5], 
                      121}}], \ 
				\ \ \ \ \ \ 
						\ \ Polygon[{{450, \(-100\), 100}, {450, \(-100\), 
                      130}, {458, \(-100\) + 5  Sin[i\ 2 + 1.2], 
                      130}, {464, \(-100\) + 10  Sin[i\ 2 + 1.2], 
                      130}, {470, \(-100\) + 15\ Sin[i\ 2 + 1.2], 
                      130}, {458, \(-100\) + 5  Sin[i\ 2 + 1.2], 
                      112}, {464, \(-100\) + 10  Sin[i\ 2 + 1.2], 
                      121}}], \ 
				\ \ \ \ \ \ \ 
						\ Polygon[{{450, \(-375\), 100}, {450, \(-375\), 
                      130}, {458, \(-375\) + 5  Sin[i\ 2 - 1.5], 
                      130}, {464, \(-375\) + 10  Sin[i\ 2 - 1.5], 
                      130}, {470, \(-375\) + 15\ Sin[i\ 2 - 1.5], 
                      130}, {458, \(-375\) + 5  Sin[i\ 2 - 1.5], 
                      112}, {464, \(-375\) + 10  Sin[i\ 2 - 1.5], 
                      121}}]}, \ \ 
				\ \ \ \ \ \ \ {RGBColor[ .875, 
                  1,  .001], \ 
					\ \ \ \ \ Polygon[{{230, 230, 
                      100}, {230, 230, 115}, {240, 230 + 13\ Sin[i\ 2 -  .4], 
                      115}}], \ 
					\ \ \ \ \ Polygon[{{150, 230, 
                      100}, {150, 230, 115}, {160, 
                      230 - 13\ Sin[i\ 2 + \  .3], 
                      115}}]}}\ ; \ \ \ \ \ 
			\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
			\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*Equations\ of\ \(Motion!\)*) 
\ \ \ \ \ angle = 
            Which[\((vPitch < 70)\), 
              Random[Real, {45, 60} // N], \((vPitch >= 70)\), 
              Random[Real, {30, 45} // 
                  N]]; 
\ \ \ \ \ \ \ vx0 = \(( .25\ vPitch\ Cos[
                      angle\ Degree] + 1.25\ vBat\ Cos[angle\ Degree])\) // 
              N; 
\ \ \ \ \ \ \ vz0 = \(( .25\ vPitch\ Sin[angle\ Degree] + 
                  1.25\ vBat\ Sin[angle\ Degree])\) // N; 

		sol = 
            NDSolve[{\(\(x'\)'\)[
                    t] == \(- .00165\)\ Sqrt[\(x'\)[t]^2 + \(z'\)[
                            t]^2]\ \(x'\)[
                      
                      t], 
				\ \ 	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\(z'\)'\)[
                    t] == \(- .00165\)\ Sqrt[\(x'\)[t]^2 + \(z'\)[
                              t]^2]\ \(z'\)[t] - 
                    32, 
					\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ x[0] == 3, 
                z[0] == 
                  4, 
				\ \ 	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(x'\)[0] == vx0, \(z'\)[0] == 
                  vz0}, 
				\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {x, z}, {t, 0, 10}]; 
		x[t_] = 
            x[t] /. sol[\([1]\)]; 
		z[t_] = 
            z[t] /. sol[\([1]\)]; 
	\ \ y[t_] = 
            x[t]\ Random[
                Real, {\(-1\), 
                  1}]; \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 
			\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ tmax = 
            t /. \ FindRoot[
                z[t] == 0, {t, 
                  10}]; 
	\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ x1max = 
            N[x[tmax], 
              4]; 
				\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ y2max = 
            N[y[tmax], 
              4]; 
				 (*Do\ Loop\ and\ Graphics*) 
		
		Do[
            Show[
				
			\ \ \ ParametricPlot3D[\ 
					\ \ \ {x[t]\ , y[t], \ z[t]\ }, {t, 0, tmax}, BoxRatios -> {1, 1, 1}, 
                DisplayFunction -> 
                  Identity], 
				
				
				Graphics3D[{AbsolutePointSize[6.5], RGBColor[1,  .01,  .01], 
                  Point[{x[t]\  /. t -> i, y[t] /. t -> i, 
                      z[t]\  /. 
                        t -> i}]}], 
				
				Graphics3D[\ 
					\ \ {AbsolutePointSize[2], RGBColor[ .001,  .01,  .001], 
                  Point[{x[t]\  /. t -> i, y[t] /. t -> i, 
                      0}]}], 
			
				Graphics3D[
                Join[g1, g2, g3, g4, g5, g6, g7, g8, g9, 
                  gr]], 
				
				Graphics3D[
                Text[StyleForm[\ \ x1max\ \ "ft 
  Hit", 
                    FontSize -> 11], {195, 220, 
                    65}]], 
			
				Graphics3D[
                Text[StyleForm[
                    Which[
							
								x1max > 400 && 
                        y2max <= 100 && 
                        y2max >= \(-100\), "Home-Run in 
  Center!", 
                      x1max < 100, "You're Out!", 
                      x1max < 200, "Single", x1max < 300, "Double", 
                      x1max > \((\(-y2max\) + 2100)\)/5 && 
                        y2max > 100, "Home-Run in 
Left Field!", 
                      x1max > \((y2max + 2100)\)/5 && 
                        y2max < \(-100\), "Home-Run in 
Right Field!", 
                      x1max < 
                        400, "Triple"]\ \ \ \ \ \ 
							\ \ , 
                    FontSize -> 18, FontWeight -> "Bold"], {400, 170, 
                    250}]], 
		
				ViewPoint -> {\(- .1\), \(-5\), 
                  4}, PlotRange -> {{0, 500}, {\(-400\), 400}, {0, 
                    400}}, 
				Boxed -> False, Axes -> False, 
              Lighting -> False, 
              ImageSize -> {600, 
                  600}, 
				DisplayFunction -> $DisplayFunction], {i, 
              0, tmax +  .01,  .2}]];\)\(
\)\)\)

\(\(\(baseBall[80, 100]\)\(
\)\(
\)\)\)