PK 2Code/PK 2Code/Csharp_Code/PK 2%Code/Csharp_Code/Chapter03_Newtonian/PK{C2y 3Code/Csharp_Code/Chapter03_Newtonian/GravityGame.csko6{~(VY;qm .RȺ VwhEUHޙ[l.3{U`}u)oU^{5-,aT`E+>?{g?Xӊck}^L[S"\TY\P-':NLuyU\~# `];H״0/_2vQĞL(+^NB]++ p^s[Ph6} X)%X(  ?#CgQv;$[15W*KΫDח|EgoxۉbM${H4QN&a%o#ٖnyQLZ+wW " ] ߊZg O =JGosE{v#eehע;8ἶh',41?`k~Df\5y oY-[f˕'?vo`'Д)П'BRGػ+Wg-G& O^t̼mn8?U%}ٺ6qQ VS}ހeK%{ =\,R!J_^wK'%o! %{ʕpLߎa%!h a ^wNeU&o xL>k$Y;^:b.p%j/,>v wp- 2 E' L,3d#8rCEMLʨP Bʆ B;C#X ƣl9swr-bWgq|p|A03EO_dg_tF(,T¼-âL߳&!hb#Wޔ֏MvL~%J|1,Q@fރG%y*ٷ_h'V1>x0Ov=v`k=( gq$sk lבs&EuC(SL੎'t^0gjQ"fxvRxS畚Fdg W;{c75$wx:A/B:z1SS܁`̬*bz?q#ThL;ǼY;qs vƽS[U%ˆ45֜lq|]P >Y[z?A;Pp;3GifyٚX0FX耦5ݒYykX;[S-F j\sE߶軱Va+/Jާ."n*.zNX)('̂-Cr[MM#`\/GڈN^؆լc{xU|@̱Xy&԰ $@| :<N*]UF n OYsAaW%W7CnL'vE#0 Oo)`v޽7hCŤzW.jp=$&-xF(+JA̠ۼ\F- m]i4>|E(Me?"Gt4J˅/=J*-j/]'Ry 5N(+'2HԬL3o#;}]{3ˈ*_ٳϢ{I W<6ķ 6&~d_UN$>")4PK2Q(k;A/Code/Csharp_Code/Chapter03_Newtonian/README.txts-IUHMK)VPJ.NVp/J,,tOMK.g&'yPKC24Code/Csharp_Code/Chapter03_Newtonian/Shuffleboard.csX[o6~@Ii]UNe4i {%:"I9)r2Hes#N4gM3%}%ek%^ ~YT@EsfD!BF&_ OD< B=މ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3Pu}6w4ZNԬ.Ym{cysZΤ;o~~"o. uh,ZwMo "$e|۽!AvkƑݰ-?-wF>úku|qe麍wvW+$[KèqJkP@P5χi ,=/ g6ux_StmRw j _/$,nm Ol̰ _4i]o,S(0|͊?]CX5ŏ:V(Inka})G}݈ĐJg?'φ> "Wu8,γFIεi-=G5m/ yiH-:goB}^5zuۉK𥹳/ a[xӈ ْ?Ҙv@ xUzt-n[X{)UHalׯ|i(ٷHx^'5;P)n:մcNcY$G;Y~~?{l?_xw  ¾#_uS]iچy.{KG/.bIH}WM+㑗 `Т`&ncw`ͧobpUh?`?cYo+ şi[6"[zzbd賘@h@@G'7.? %R_}+YwךkZ%G8,jڠm@Rkj~zW]'$w5>_ moG Cդj o?U%-˷QZ7X0[Ox"ee $_ @eH N(6$,v;2%7ErT7: 6 _֟u>dv-]z8]wTK9u CȊHy QCm;_|I7Ú|O[Əx^ծL9 Jq;B Vbur| p|k]SO|i/xo5Ok;ky5 )v^{MZ6kMǵK}HtP@~?óxP|- Gwmoh+ zN$fMA+L<_IgυO >"xUuy&xMn iZ-F0Gs=ܑR9#K{kgM?[4/{!yǿo >oxj@]~/dӍɍe$ I ^MhZH'Xݕ@ۭ"k_%<Ǿ''ŪvZ4rEֵڒͼjCH,*۠ۧǯa?iρ~$Uτ5_:MWV_,Rk]hf7x<韣P@P@P@PK U326ͪ&&.Code/Csharp_Code/Chapter04_Kinematics/blah.txtt x v 0.0 -0.2 0.0 0.1 -0.18129583 0.35911041 0.2 -0.13210082 0.6026921 0.30000000000000004 -0.06563839 0.7023594 0.4 0.0035563086 0.6599471 0.5 0.062472187 0.50297004 0.6 0.10178518 0.27602664 0.7 0.11704715 0.030280279 0.7999999999999999 0.1088193 -0.18679355 0.8999999999999999 0.081872545 -0.33956036 0.9999999999999999 0.043730844 -0.40908346 1.0999999999999999 0.0029145665 -0.39425683 1.2 -0.03275344 -0.3095257 1.3 -0.05747879 -0.18008539 1.4000000000000001 -0.06827096 -0.03578604 1.5000000000000002 -0.065098986 0.09496394 1.6000000000000003 -0.05048524 0.190183 1.7000000000000004 -0.028689645 0.23743455 1.8000000000000005 -0.00469026 0.23476876 1.9000000000000006 0.016825354 0.18961914 2.0000000000000004 0.032275382 0.116139665 2.1000000000000005 0.039683703 0.031685945 2.2000000000000006 0.03881714 -0.046798542 2.3000000000000007 0.030985467 -0.10581791 2.400000000000001 0.018587602 -0.13730763 2.500000000000001 0.0045221243 -0.13935079 2.600000000000001 -0.008411368 -0.115672424 2.700000000000001 -0.018009525 -0.074174404 2.800000000000001 -0.022984458 -0.024911713 2.9000000000000012 -0.023071447 0.022042613 3.0000000000000013 -0.018934853 0.058438756 3.1000000000000014 -0.0119175585 0.07910229 3.2000000000000015 -0.003701404 0.082450755 3.3000000000000016 0.0040469854 0.07028261 3.4000000000000017 0.009978312 0.04697844 3.5000000000000018 0.013262744 0.01834198 3.600000000000002 0.013669101 -0.009657374 3.700000000000002 0.0115237385 -0.031997263 3.800000000000002 0.0075733913 -0.045387372 3.900000000000002 0.002790352 -0.04862897 4.000000000000002 -0.0018363965 -0.04254268 4.100000000000001 -0.0054840352 -0.029537639 4.200000000000001 -0.0076229824 -0.012950656 4.300000000000001 -0.008072753 0.00369198 4.4 -0.0069863256 0.017344566 4.5 -0.004775805 0.02593107 4.6 -0.0020011384 0.028589137 4.699999999999999 7.5267383E-4 0.02565861 4.799999999999999 0.0029858516 0.018452177 4.899999999999999 0.0043632044 0.008880373 4.999999999999998 0.0047524124 -9.803753E-4 5.099999999999998 0.0042199474 -0.009289871 5.1999999999999975 0.002991272 -0.014747176 5.299999999999997 0.0013875596 -0.016753044 5.399999999999997 -2.462542E-4 -0.015421648 5.4999999999999964 -0.0016077429 -0.011460463 5.599999999999996 -0.0024862783 -0.005958545 5.699999999999996 -0.0027887034 -1.346389E-4 5.799999999999995 -0.002539989 0.0049033463 5.899999999999995 -0.0018622365 0.008345148 5.999999999999995 -9.3887124E-4 0.009784634 6.099999999999994 2.7373811E-5 0.009237697 6.199999999999994 8.5415214E-4 0.007080622 6.299999999999994 0.0014099524 0.0039312397 6.399999999999993 0.0016310298 5.0253794E-4 6.499999999999993 0.0015236111 -0.0025407337 6.5999999999999925 0.0011530208 -0.0046966937 6.699999999999992 6.235314E-4 -0.0056952774 6.799999999999992 5.3909884E-5 -0.005515271 6.8999999999999915 -4.462796E-4 -0.0043535545 6.999999999999991 -7.953948E-4 -0.0025588104 7.099999999999991 -9.5073273E-4 -5.4674974E-4 t x v 0.0 -0.2 0.0 0.035 -0.1975972125350572 0.0 0.07 -0.1906106909587706 0.0 0.105 -0.17944128748320448 0.0 0.14 -0.1645689857600239 0.0 0.175 -0.14653742077706927 0.0 0.21 -0.12593767436537393 0.0 0.245 -0.10339176934561968 0.0 0.28 -0.07953627088511676 0.0 0.315 -0.05500638018606956 0.0 0.35 -0.030420874201642793 0.0 0.385 -0.006368206834508681 0.0 0.42 0.016605956727282538 0.0 0.455 0.038009548912558214 0.0 0.49 0.05741307918318306 0.0 0.525 0.07445666365107018 0.0 0.56 0.08885503717932133 0.0 0.595 0.10040053177000016 0.0 0.63 0.1089640543110927 0.0 0.665 0.11449414271754355 0.0 0.7 0.11701422123026288 0.0 0.735 0.1166182123552359 0.0 0.77 0.11346469401400851 0.0 0.805 0.10776981548425847 0.0 0.84 0.09979920435027724 0.0 0.875 0.08985910883957979 0.0 0.91 0.07828702563563647 0.0 0.945 0.06544206272129319 0.0 0.98 0.051695280355191456 0.0 1.015 0.03742024137072414 0.0 1.05 0.02298398517679976 0.0 1.085 0.008738618782839299 0.0 1.12 -0.004986306414262713 0.0 1.155 -0.01789049068998005 0.0 1.19 -0.02970854282325528 0.0 1.225 -0.040214516109188095 0.0 1.26 -0.04922527283370698 0.0 1.295 -0.056602656989915914 0.0 1.33 -0.062254484436832326 0.0 1.365 -0.06613438739834657 0.0 1.4 -0.06824057560187378 0.0 1.435 -0.0686135989747015 0.0 1.47 -0.06733321625503788 0.0 1.505 -0.06451448983383809 0.0 1.54 -0.06030323942047507 0.0 1.575 -0.05487099561612438 0.0 1.61 -0.048409599174745806 0.0 1.645 -0.041125592715007854 0.0 1.68 -0.033234549083859366 0.0 1.715 -0.024955474706125805 0.0 1.75 -0.016505417393185555 0.0 1.785 -0.008094396591723915 0.0 1.82 7.923966095107355E-5 0.0 1.855 0.007832942305175627 0.0 1.89 0.01500350139940711 0.0 1.925 0.02144994455365045 0.0 1.96 0.02705575743773863 0.0 1.995 0.03173040814646547 0.0 2.03 0.0354101747169825 0.0 2.065 0.038058291728329335 0.0 2.1 0.03966444731720636 0.0 2.135 0.040243675814122304 0.0 2.17 0.03983470328794886 0.0 2.205 0.03849781338821597 0.0 2.24 0.03631230885397747 0.0 2.275 0.033373649834224195 0.0 2.31 0.029790353712727816 0.0 2.345 0.02568074247932019 0.0 2.38 0.021169622920272337 0.0 2.415 0.016384982139310163 0.0 2.45 0.01145477633553244 0.0 2.485 0.006503884557588159 0.0 2.52 0.001651291555719301 0.0 2.555 -0.0029924448832181626 0.0 2.59 -0.007327396341536249 0.0 2.625 -0.011266100348877945 0.0 2.66 -0.01473500609726455 0.0 2.695 -0.01767551484807515 0.0 2.73 -0.02004461097895287 0.0 2.765 -0.021815089576544263 0.0 2.8 -0.022975395788910963 0.0 2.835 -0.023529099620940706 0.0 2.87 -0.023494037328276308 0.0 2.905 -0.022901156913198904 0.0 2.94 -0.021793110355846284 0.0 2.975 -0.02022263906621943 0.0 3.01 -0.01825080159023558 0.0 3.045 -0.015945093852643883 0.0 3.08 -0.013377512207568 0.0 3.115 -0.010622608358588146 0.0 3.15 -0.007755582894633846 0.0 3.185 -0.00485046087728595 0.0 3.22 -0.001978388739137818 0.0 3.255 7.939131446407519E-4 0.0 3.29 0.0034055133148942545 0.0 3.325 0.005802424494845078 0.0 3.36 0.007938534364046025 0.0 3.395 0.00977630115135865 0.0 3.43 0.011287209506913476 0.0 3.465 0.012451988055197996 0.0 3.5 0.01326059563629149 0.0 3.535 0.013711988393572655 0.0 3.57 0.013813684464462524 0.0 3.605 0.013581146994692561 0.0 3.64 0.013037009464229744 0.0 3.675 0.012210169842126365 0.0 3.71 0.011134781855721091 0.0 3.745 0.009849172663604383 0.0 3.78 0.008394716476744439 0.0 3.815 0.00681469321038579 0.0 3.85 0.00515316011843903 0.0 3.885 0.0034538626232367194 0.0 3.92 0.0017592082792492656 0.0 3.955 1.0932508119255598E-4 0.0 3.99 -0.0014587777668868525 0.0 4.025 -0.0029119318720964354 0.0 4.06 -0.004221403259540335 0.0 4.095 -0.005363349994026493 0.0 4.13 -0.00631913987146344 0.0 4.165 -0.007075527769592956 0.0 4.2 -0.007624695611507276 0.0 4.235 -0.00796416101681062 0.0 4.27 -0.00809656353234949 0.0 4.305 -0.008029339795621293 0.0 4.34 -0.007774301048853197 0.0 4.375 -0.007347128061409564 0.0 4.41 -0.00676679971532712 0.0 4.445 -0.006054972257512034 0.0 4.48 -0.005235326527561022 0.0 4.515 -0.004332900347688105 0.0 4.55 -0.0033734227356523702 0.0 4.585 -0.0023826657060271594 0.0 4.62 -0.0013858281998794183 0.0 4.655 -4.069651739909016E-4 0.0 4.69 5.3152686140192E-4 0.0 4.725 0.0014093584893189617 0.0 4.76 0.002208722896930881 0.0 4.795 0.0029145930468129303 0.0 4.83 0.0035149374368828915 0.0 4.865 0.004000853473610222 0.0 4.9 0.004366619495365892 0.0 4.935 0.004609668367447156 0.0 4.97 0.004730487288995111 0.0 5.005 0.004732449972276406 0.0 5.04 0.004621588650561764 0.0 5.075 0.004406314422720113 0.0 5.11 0.0040970952380767435 0.0 5.145 0.0037061013582266504 0.0 5.18 0.003246828404065815 0.0 5.215 0.0027337081132139058 0.0 5.25 0.0021817167078722974 0.0 5.285 0.0016059903237350393 0.0 5.32 0.0010214562990225958 0.0 5.355 4.4248829489692285E-4 0.0 5.39 -1.1740775682569632E-4 0.0 5.425 -6.458709748431152E-4 0.0 5.46 -0.001131921391460164 0.0 5.495 -0.0015661508599149416 0.0 5.53 -0.0019408667579536478 0.0 5.565 -0.0022501874790040893 0.0 5.6 -0.0024900899022713826 0.0 5.635 -0.0026584101671223814 0.0 5.67 -0.0027548001215972067 0.0 5.705 -0.002780642749490643 0.0 5.74 -0.0027389306885395905 0.0 5.775 -0.002634112621058038 0.0 5.81 -0.00247191283907199 0.0 5.845 -0.0022591296537938783 0.0 5.88 -0.0020034185332014637 0.0 5.915 -0.0017130659143225352 0.0 5.95 -0.0013967595548059326 0.0 5.985 -0.00106336107084309 0.0 6.02 -7.2168596760414E-4 0.0 6.055 -3.8029601849858376E-4 0.0 6.09 -4.730830705156001E-5 0.0 6.125 2.697753723376872E-4 0.0 6.16 5.642157324699187E-4 0.0 6.195 8.301575194677277E-4 0.0 6.23 0.0010627237663108201 0.0 6.265 0.001258081923606934 0.0 6.3 0.0014134817307679605 0.0 6.335 0.0015272653708826446 0.0 6.37 0.0015988510849732 0.0 6.405 0.0016286919933704575 0.0 6.44 0.0016182123731021446 0.0 6.475 0.0015697240621494956 0.0 6.51 0.0014863259981886816 0.0 6.545 0.001371790147331658 0.0 6.58 0.0012304372360560896 0.0 6.615 0.0010670057678250585 0.0 6.65 8.865177877873708E-4 0.0 6.685 6.941447592703674E-4 0.0 6.72 4.950767410748423E-4 0.0 6.755 2.9439781285502565E-4 0.0 6.79 9.697039630059858E-5 0.0 6.825 -9.266922747312518E-5 0.0 6.86 -2.704022882624342E-4 0.0 6.895 -4.326042790989252E-4 0.0 6.93 -5.762060100216854E-4 0.0 6.965 -6.987383119531429E-4 0.0 7.0 -7.983601620904432E-4 0.0 PK 2y+,Code/Csharp_Code/Chapter04_Kinematics/ODE.csusing System; public abstract class ODE { // Declare fields used by the class private int numEqns; // number of equations to solve private double[] q; // array of dependent variables private double s; // independent variable // Constructor public ODE(int numEqns) { this.numEqns = numEqns; q = new double[numEqns]; } // These properties access the value of the numEqns // and s fields. public int NumEqns { get { return numEqns; } } public double S { get { return s; } set { s = value; } } // This method returns the entire q[] array. public double GetQ(int index) { return q[index]; } public void SetQ(double value, int index) { q[index] = value; return; } public double[] GetAllQ() { return q; } // This method returns the right-hand side of the // ODEs. It is declared abstract to force subclasses // to implement their own version of the method. public abstract double[] GetRightHandSide(double s, double[] q,double[] deltaQ, double ds, double qScale); } PK 2͞FF2Code/Csharp_Code/Chapter04_Kinematics/ODESolver.csusing System; public class ODESolver { // Fourth-order Runge-Kutta ODE solver. public static void RungeKutta4(ODE ode, double ds) { // Define some convenience variables to make the // code more readable int j; int numEqns = ode.NumEqns; double s; double[] q; double[] dq1 = new double[numEqns]; double[] dq2 = new double[numEqns]; double[] dq3 = new double[numEqns]; double[] dq4 = new double[numEqns]; // Retrieve the current values of the dependent // and independent variables. s = ode.S; q = ode.GetAllQ(); // Compute the four Runge-Kutta steps, The return // value of getRightHandSide method is an array of // delta-q values for each of the four steps. dq1 = ode.GetRightHandSide(s, q, q, ds, 0.0); dq2 = ode.GetRightHandSide(s+0.5*ds, q, dq1, ds, 0.5); dq3 = ode.GetRightHandSide(s+0.5*ds, q, dq2, ds, 0.5); dq4 = ode.GetRightHandSide(s+ds, q, dq3, ds, 1.0); // Update the dependent and independent variable values // at the new dependent variable location and store the // values in the ODE object arrays. ode.S = s + ds; for(j=0; jPs% іxZ]}ګ̗zi/ |U⧇/ouQ]_7k\agzEӪ6{a}%@̗6Ŧ0C _WY$R]$]ݮ| J.,>&?iJΕXR$qQ台WI|Um~յ^5n<`֑>}?M9_YJLm/CԘ71G^ GS&Q3NM$okR>;冧N59:P}+j:*Qm6y_h5cXxi:Ɓx˿D/mj^Mk ֧ꚍ h` Y{1T0JTh?\僩=*JRWѫ;V+'d*b:ᇋ5:VyFb"(I188C*:zNtQ:qʵ^JUiJ4+F3鶚]W7kui2 nIc20#)u\~SNS*rt 8.-=˵М8l%o7ΥkjڞO ^jLuqtIkej˪Tj-Je?J[Y(J(cq0c14ܱHw/|+(Eޛ=h铜ՔZ"!ծl2 sZ{5jGKMZ?|2ɰ[Ͳ;4'^_ST'+|C?}Si ۭ-VNWaTb=ZNi9~-b~fnh[r3pF=OR (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קNuJJq ue9Tj젒9ìNW9'(ߤ:r#hz4: MQ-CG[h8.gM8΍>Ce9vA`jf/N4eJRJ|?5zQVTiF/_,!ౙIR5Skhh |Ѽ_p[Q |A'O i ˣ[k\ǯ"OZ}ZׇmYt==9eJĮ%ٖeK-+*pq: ˳,˫՚OT͜M|Cf9Rk Qэ:4*s\PʬoE#0>x=#d#>#ivDm/ Z&[w[[Ǘx#LFXNAʌ`Q_Rmm 9hI$C'd8.{j؉9Zxm-k¿,> ZkZ'Ë6m%^X7.ٴKkK{]>;'nVP({eѯbVT0s:Uԫ:x[jsf^0ydi`p0LcӢ 02]_ ׽T#"<ڮaB> 51 QX|=XF% R䨕? ^*mg}f_g g1l-ܗ:L)im[6NJ͌I^' aa1abiʕZS9qqe]8-{)VbcT)SwRqI){5IJv [?Xw~m^8|%W{qw+t3fq<bjb)''G bcF-#VUed)E$9ae߅tG՚9%; ֊HH:oxY8hiڕ r5 ,{QW5`d`3U9%zGPPK RC2aq&&1Code/Csharp_Code/Chapter05_Projectile/GolfGame.csusing System; using System.Windows.Forms; using System.Drawing; public class GolfGame : Form { private Label vxLabel; private Label vyLabel; private Label vzLabel; private Label distanceLabel; private Label axesLabel; private TextBox vxTextBox; private TextBox vyTextBox; private TextBox vzTextBox; private TextBox distanceTextBox; private ComboBox axesComboBox; private Button fireButton; private Button resetButton; private Panel drawingPanel; // This field is for the images used in the game. private Image golferIcon; private Image flagIcon; // The Timer is used to control the execution speed // of the game. private Timer gameTimer; // The golf ball is a SimpleProjectile private SimpleProjectile golfball; // The player can control the distance to the hole. private double distanceToHole; public GolfGame() { // Create a SimpleProjectile object with default values so // the display can be updated the first time. golfball = new SimpleProjectile(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // Set up images golferIcon = Image.FromFile("Golfer.jpg"); flagIcon = Image.FromFile("Hole_Cartoon.jpg"); // Initialize the distanceToHole field. distanceToHole = 200.0; // Create a Timer object that will be used // to slow the action down. gameTimer = new Timer(); gameTimer.Interval = 50; // delay in milliseconds. gameTimer.Tick += new EventHandler(ActionPerformed); // Create some Labels vxLabel = new Label(); vxLabel.Text = "Initial x-velocity, m/s"; vxLabel.Font = new Font(vxLabel.Font, FontStyle.Bold); vxLabel.Top = 50; vxLabel.Left = 10; vxLabel.Width = 130; vyLabel = new Label(); vyLabel.Text = "Initial y-velocity, m/s"; vyLabel.Font = new Font(vyLabel.Font, FontStyle.Bold); vyLabel.Top = 80; vyLabel.Left = 10; vyLabel.Width = 130; vzLabel = new Label(); vzLabel.Text = "Initial z-velocity, m/s"; vzLabel.Font = new Font(vzLabel.Font, FontStyle.Bold); vzLabel.Top = 110; vzLabel.Left = 10; vzLabel.Width = 130; distanceLabel = new Label(); distanceLabel.Text = "Distance to hole, m"; distanceLabel.Font = new Font(distanceLabel.Font, FontStyle.Bold); distanceLabel.Top = 140; distanceLabel.Left = 10; distanceLabel.Width = 120; axesLabel = new Label(); axesLabel.Text = "View axes"; axesLabel.Font = new Font(axesLabel.Font, FontStyle.Bold); axesLabel.Top = 170; axesLabel.Left = 10; axesLabel.Width = 70; // Create TextBox objects to display the inputs. vxTextBox = new TextBox(); vxTextBox.Width = 50; vxTextBox.Text = "31.0"; vxTextBox.AutoSize = true; vxTextBox.Top = vxLabel.Top; vxTextBox.Left = 150; vyTextBox = new TextBox(); vyTextBox.Width = 50; vyTextBox.Text = "0.0"; vyTextBox.AutoSize = true; vyTextBox.Top = vyLabel.Top; vyTextBox.Left = 150; vzTextBox = new TextBox(); vzTextBox.Width = 50; vzTextBox.Text = "35.0"; vzTextBox.AutoSize = true; vzTextBox.Top = vzLabel.Top; vzTextBox.Left = 150; distanceTextBox = new TextBox(); distanceTextBox.Width = 50; distanceTextBox.Text = "200.0"; distanceTextBox.AutoSize = true; distanceTextBox.Top = distanceLabel.Top; distanceTextBox.Left = 150; // Create a ComboBox to select the view axes. axesComboBox = new ComboBox(); axesComboBox.Items.Add("XZ"); axesComboBox.Items.Add("XY"); axesComboBox.SelectedIndex = 0; axesComboBox.Left = 80; axesComboBox.Top = axesLabel.Top; // Create Button objects int buttonHeight = 30; int buttonWidth = 50; int buttonLeft = 20; fireButton = new Button(); fireButton.Text = "Fire"; fireButton.Height = buttonHeight; fireButton.Width = buttonWidth; fireButton.Top = 200; fireButton.Left = buttonLeft; fireButton.Click += new EventHandler(FireButtonClicked); resetButton = new Button(); resetButton.Text = "Reset"; resetButton.Height = buttonHeight; resetButton.Width = buttonWidth; resetButton.Top = 250; resetButton.Left = buttonLeft; resetButton.Click += new EventHandler(ResetButtonClicked); // Create a drawing panel. drawingPanel = new Panel(); drawingPanel.Width = 501; drawingPanel.Height = 201; drawingPanel.Left = 20; drawingPanel.Top = 300; drawingPanel.BorderStyle = BorderStyle.FixedSingle; // Add the GUI components to the Form this.Controls.Add(vxLabel); this.Controls.Add(vyLabel); this.Controls.Add(vzLabel); this.Controls.Add(distanceLabel); this.Controls.Add(axesLabel); this.Controls.Add(vxTextBox); this.Controls.Add(vyTextBox); this.Controls.Add(vzTextBox); this.Controls.Add(distanceTextBox); this.Controls.Add(axesComboBox); this.Controls.Add(fireButton); this.Controls.Add(resetButton); this.Controls.Add(drawingPanel); // Set the size and title of the form this.Width = 600; this.Height = 550; this.Text = "Golf Game"; // Center the form on the screen and make // it visible. this.StartPosition = FormStartPosition.CenterScreen; this.Visible = true; // Update the GUI display UpdateDisplay(); } // Event handling method for the "Fire" button public void FireButtonClicked(object source, EventArgs e) { // Get the initial values from the textfield double vx0 = Convert.ToDouble(vxTextBox.Text); double vy0 = Convert.ToDouble(vyTextBox.Text); double vz0 = Convert.ToDouble(vzTextBox.Text); distanceToHole = Convert.ToDouble(distanceTextBox.Text); // Create a SimpleProjectile object representing the golf ball. golfball = new SimpleProjectile(0.0, 0.0, 0.0, vx0, vy0, vz0, 0.0); // Update the display UpdateDisplay(); // Fire the golf ball using a Timer object // to slow down the action. gameTimer.Start(); } // Event handling method for the "Reset" button public void ResetButtonClicked(object source, EventArgs e) { // stop the timer. gameTimer.Stop(); // Reset the time, location, and velocity of ball; golfball.S = 0.0; // time golfball.SetQ(0.0,0); // vx0 golfball.SetQ(0.0,1); // x0 golfball.SetQ(0.0,2); // vy0 golfball.SetQ(0.0,3); // y0 golfball.SetQ(0.0,4); // vz0 golfball.SetQ(0.0,5); // z0 // Reset the distance to hole. distanceToHole = Convert.ToDouble(distanceTextBox.Text); // Update the display. UpdateDisplay(); } // This method redraws the GUI display. private void UpdateDisplay() { Graphics g = drawingPanel.CreateGraphics(); int width = drawingPanel.Width - 1; int height = drawingPanel.Height - 1; // Clear the current display. // g.Clear(drawingPanel.BackColor); g.Clear(Color.White); // Update the position of the golfball on the screen. SolidBrush brush = new SolidBrush(Color.Black); Pen blackPen = new Pen(Color.Black, 1); // Draw picture based on whether the XZ or // XY axes are selected. string axes = (string)axesComboBox.SelectedItem; if ( String.Equals(axes, "XZ") ) { // Draw the golfer. int zLocation = height - 50; g.DrawImage(golferIcon, 0, zLocation, 34, 50); // Draw the flag zLocation = height - 62; g.DrawImage(flagIcon, (int)(2.0*distanceToHole), zLocation, 55, 62); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX() + 14); int zPosition = (int)(height - 5 - 2.0*golfball.GetZ()); g.FillEllipse(brush, xPosition, zPosition, 5, 5); } else { // Draw location of green. g.DrawEllipse(blackPen, (int)(2.0*distanceToHole - 20), 80, 40, 40); g.FillEllipse(brush, (int)(2.0*distanceToHole - 4), 96, 8, 8); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX()); int yPosition = (int)(100 - 2 - 2.0*golfball.GetY()); g.FillEllipse(brush, xPosition, yPosition, 5, 5); } // Clean up the Graphics object. g.Dispose(); } // This method is called by the Timer every 0.05 seconds. public void ActionPerformed(object source, EventArgs e) { // Update the time and compute the new position // of the golfball. double timeIncrement = 0.07; golfball.UpdateLocationAndVelocity(timeIncrement); // Update the display UpdateDisplay(); // Access the Graphics object of the drawing panel. Graphics g = drawingPanel.CreateGraphics(); // When the golfball hits the ground, stop the simulation // and see where ball has landed. if ( golfball.GetZ() <= 0.0 ) { Console.WriteLine("time="+(float)golfball.GetTime()+ " x="+(float)golfball.GetX()+ " y="+(float)golfball.GetY()+" z="+(float)golfball.GetZ()); // Stop the simulation gameTimer.Stop(); // Determine if ball is on the green. SolidBrush brush = new SolidBrush(Color.Black); Font font = new Font("Arial", 12); if ( golfball.GetX() > distanceToHole - 10.0 && golfball.GetX() < distanceToHole + 10.0 && golfball.GetY() < 10.0) { g.DrawString("You're on the green", font, brush, 100, 30); } else { g.DrawString("You missed", font, brush, 100, 30); } } } static void Main() { Application.Run(new GolfGame()); } } PK VC2Jd0d02Code/Csharp_Code/Chapter05_Projectile/GolfGame2.csusing System; using System.Windows.Forms; using System.Drawing; public class GolfGame2 : Form { private Label vxLabel; private Label vyLabel; private Label vzLabel; private Label distanceLabel; private Label axesLabel; private Label massLabel; private Label areaLabel; private Label cdLabel; private Label densityLabel; private TextBox vxTextBox; private TextBox vyTextBox; private TextBox vzTextBox; private TextBox distanceTextBox; private TextBox massTextBox; private TextBox areaTextBox; private TextBox cdTextBox; private TextBox densityTextBox; private ComboBox axesComboBox; private Button fireButton; private Button resetButton; private Panel drawingPanel; // This field is for the images used in the game. private Image golferIcon; private Image flagIcon; // The Timer is used to control the execution speed // of the game. private Timer gameTimer; // The golf ball is a DragProjectile private DragProjectile golfball; // The player can control the distance to the hole. private double distanceToHole; public GolfGame2() { // Create a DragProjectile object with default values // so the display can be updated the first time. golfball = new DragProjectile(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0459, 0.001432, 0.5, 1.225); // Set up images golferIcon = Image.FromFile("Golfer.jpg"); flagIcon = Image.FromFile("Hole_Cartoon.jpg"); // Initialize the distanceToHole field. distanceToHole = 200.0; // Create a Timer object that will be used // to slow the action down. gameTimer = new Timer(); gameTimer.Interval = 50; // delay in milliseconds. gameTimer.Tick += new EventHandler(ActionPerformed); // Create some Labels vxLabel = new Label(); vxLabel.Text = "Initial x-velocity, m/s"; vxLabel.Font = new Font(vxLabel.Font, FontStyle.Bold); vxLabel.Top = 50; vxLabel.Left = 10; vxLabel.Width = 130; vyLabel = new Label(); vyLabel.Text = "Initial y-velocity, m/s"; vyLabel.Font = new Font(vyLabel.Font, FontStyle.Bold); vyLabel.Top = 80; vyLabel.Left = 10; vyLabel.Width = 130; vzLabel = new Label(); vzLabel.Text = "Initial z-velocity, m/s"; vzLabel.Font = new Font(vzLabel.Font, FontStyle.Bold); vzLabel.Top = 110; vzLabel.Left = 10; vzLabel.Width = 130; distanceLabel = new Label(); distanceLabel.Text = "Distance to hole, m"; distanceLabel.Font = new Font(distanceLabel.Font, FontStyle.Bold); distanceLabel.Top = 140; distanceLabel.Left = 10; distanceLabel.Width = 120; massLabel = new Label(); massLabel.Text = "mass, kg"; massLabel.Font = new Font(massLabel.Font, FontStyle.Bold); massLabel.Top = 50; massLabel.Left = 210; massLabel.Width = 110; areaLabel = new Label(); areaLabel.Text = "area, m^2"; areaLabel.Font = new Font(areaLabel.Font, FontStyle.Bold); areaLabel.Top = 80; areaLabel.Left = 210; areaLabel.Width = 110; cdLabel = new Label(); cdLabel.Text = "drag coefficient"; cdLabel.Font = new Font(cdLabel.Font, FontStyle.Bold); cdLabel.Top = 110; cdLabel.Left = 210; cdLabel.Width = 110; densityLabel = new Label(); densityLabel.Text = "density, kg/m^3"; densityLabel.Font = new Font(densityLabel.Font, FontStyle.Bold); densityLabel.Top = 140; densityLabel.Left = 210; densityLabel.Width = 110; axesLabel = new Label(); axesLabel.Text = "View axes"; axesLabel.Font = new Font(axesLabel.Font, FontStyle.Bold); axesLabel.Top = 170; axesLabel.Left = 10; axesLabel.Width = 70; // Create TextBox objects to display the inputs. vxTextBox = new TextBox(); vxTextBox.Width = 50; vxTextBox.Text = "31.0"; vxTextBox.AutoSize = true; vxTextBox.Top = vxLabel.Top; vxTextBox.Left = 150; vyTextBox = new TextBox(); vyTextBox.Width = 50; vyTextBox.Text = "0.0"; vyTextBox.AutoSize = true; vyTextBox.Top = vyLabel.Top; vyTextBox.Left = 150; vzTextBox = new TextBox(); vzTextBox.Width = 50; vzTextBox.Text = "35.0"; vzTextBox.AutoSize = true; vzTextBox.Top = vzLabel.Top; vzTextBox.Left = 150; distanceTextBox = new TextBox(); distanceTextBox.Width = 50; distanceTextBox.Text = "200.0"; distanceTextBox.AutoSize = true; distanceTextBox.Top = distanceLabel.Top; distanceTextBox.Left = 150; massTextBox = new TextBox(); massTextBox.Width = 60; massTextBox.Text = "0.0459"; massTextBox.AutoSize = true; massTextBox.Top = massLabel.Top; massTextBox.Left = 330; areaTextBox = new TextBox(); areaTextBox.Width = 60; areaTextBox.Text = "0.001432"; areaTextBox.AutoSize = true; areaTextBox.Top = areaLabel.Top; areaTextBox.Left = 330; cdTextBox = new TextBox(); cdTextBox.Width = 60; cdTextBox.Text = "0.25"; cdTextBox.AutoSize = true; cdTextBox.Top = cdLabel.Top; cdTextBox.Left = 330; densityTextBox = new TextBox(); densityTextBox.Width = 60; densityTextBox.Text = "1.225"; densityTextBox.AutoSize = true; densityTextBox.Top = densityLabel.Top; densityTextBox.Left = 330; // Create a ComboBox to select the view axes. axesComboBox = new ComboBox(); axesComboBox.Items.Add("XZ"); axesComboBox.Items.Add("XY"); axesComboBox.SelectedIndex = 0; axesComboBox.Left = 80; axesComboBox.Top = axesLabel.Top; // Create Button objects int buttonHeight = 30; int buttonWidth = 50; int buttonLeft = 20; fireButton = new Button(); fireButton.Text = "Fire"; fireButton.Height = buttonHeight; fireButton.Width = buttonWidth; fireButton.Top = 200; fireButton.Left = buttonLeft; fireButton.Click += new EventHandler(FireButtonClicked); resetButton = new Button(); resetButton.Text = "Reset"; resetButton.Height = buttonHeight; resetButton.Width = buttonWidth; resetButton.Top = 250; resetButton.Left = buttonLeft; resetButton.Click += new EventHandler(ResetButtonClicked); // Create a drawing panel. drawingPanel = new Panel(); drawingPanel.Width = 501; drawingPanel.Height = 201; drawingPanel.Left = 20; drawingPanel.Top = 300; drawingPanel.BorderStyle = BorderStyle.FixedSingle; // Add the GUI components to the Form this.Controls.Add(vxLabel); this.Controls.Add(vyLabel); this.Controls.Add(vzLabel); this.Controls.Add(distanceLabel); this.Controls.Add(axesLabel); this.Controls.Add(massLabel); this.Controls.Add(areaLabel); this.Controls.Add(cdLabel); this.Controls.Add(densityLabel); this.Controls.Add(vxTextBox); this.Controls.Add(vyTextBox); this.Controls.Add(vzTextBox); this.Controls.Add(distanceTextBox); this.Controls.Add(massTextBox); this.Controls.Add(areaTextBox); this.Controls.Add(cdTextBox); this.Controls.Add(densityTextBox); this.Controls.Add(axesComboBox); this.Controls.Add(fireButton); this.Controls.Add(resetButton); this.Controls.Add(drawingPanel); // Set the size and title of the form this.Width = 600; this.Height = 550; this.Text = "Golf Game version 2"; // Center the form on the screen and make // it visible. this.StartPosition = FormStartPosition.CenterScreen; this.Visible = true; // Update the GUI display UpdateDisplay(); } // Event handling method for the "Fire" button public void FireButtonClicked(object source, EventArgs e) { // Get the initial values from the textfield double vx0 = Convert.ToDouble(vxTextBox.Text); double vy0 = Convert.ToDouble(vyTextBox.Text); double vz0 = Convert.ToDouble(vzTextBox.Text); distanceToHole = Convert.ToDouble(distanceTextBox.Text); double mass = Convert.ToDouble(massTextBox.Text); double area = Convert.ToDouble(areaTextBox.Text); double cd = Convert.ToDouble(cdTextBox.Text); double density = Convert.ToDouble(densityTextBox.Text); // Create a DragProjectile object representing the golf ball. golfball = new DragProjectile(0.0, 0.0, 0.0, vx0, vy0, vz0, 0.0, mass, area, density, cd); // Update the display UpdateDisplay(); // Fire the golf ball using a Timer object // to slow down the action. gameTimer.Start(); } // Event handling method for the "Reset" button public void ResetButtonClicked(object source, EventArgs e) { // stop the timer. gameTimer.Stop(); // Reset the time, location, and velocity of ball; golfball.S = 0.0; // time golfball.SetQ(0.0,0); // vx0 golfball.SetQ(0.0,1); // x0 golfball.SetQ(0.0,2); // vy0 golfball.SetQ(0.0,3); // y0 golfball.SetQ(0.0,4); // vz0 golfball.SetQ(0.0,5); // z0 // Reset the distance to hole. distanceToHole = Convert.ToDouble(distanceTextBox.Text); // Update the display. UpdateDisplay(); } // This method redraws the GUI display. private void UpdateDisplay() { Graphics g = drawingPanel.CreateGraphics(); int width = drawingPanel.Width - 1; int height = drawingPanel.Height - 1; // Clear the current display. g.Clear(Color.White); // Update the position of the golfball on the screen. SolidBrush brush = new SolidBrush(Color.Black); Pen blackPen = new Pen(Color.Black, 1); // Draw picture based on whether the XZ or // XY axes are selected. string axes = (string)axesComboBox.SelectedItem; if ( String.Equals(axes, "XZ") ) { // Draw the golfer. int zLocation = height - 50; g.DrawImage(golferIcon, 0, zLocation, 34, 50); // Draw the flag zLocation = height - 62; g.DrawImage(flagIcon, (int)(2.0*distanceToHole), zLocation, 55, 62); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX() + 14); int zPosition = (int)(height - 5 - 2.0*golfball.GetZ()); g.FillEllipse(brush, xPosition, zPosition, 5, 5); } else { // Draw location of green. g.DrawEllipse(blackPen, (int)(2.0*distanceToHole - 20), 80, 40, 40); g.FillEllipse(brush, (int)(2.0*distanceToHole - 4), 96, 8, 8); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX()); int yPosition = (int)(100 - 2 - 2.0*golfball.GetY()); g.FillEllipse(brush, xPosition, yPosition, 5, 5); } // Clean up the Graphics object. g.Dispose(); } // This method is called by the Timer every 0.05 seconds. public void ActionPerformed(object source, EventArgs e) { // Update the time and compute the new position // of the golfball. double timeIncrement = 0.07; golfball.UpdateLocationAndVelocity(timeIncrement); // Update the display UpdateDisplay(); // Access the Graphics object of the drawing panel. Graphics g = drawingPanel.CreateGraphics(); // When the golfball hits the ground, stop the simulation // and see where ball has landed. if ( golfball.GetZ() <= 0.0 ) { Console.WriteLine("time="+(float)golfball.GetTime()+ " x="+(float)golfball.GetX()+ " y="+(float)golfball.GetY()+" z="+(float)golfball.GetZ()); // Stop the simulation gameTimer.Stop(); // Determine if ball is on the green. SolidBrush brush = new SolidBrush(Color.Black); Font font = new Font("Arial", 12); if ( golfball.GetX() > distanceToHole - 10.0 && golfball.GetX() < distanceToHole + 10.0 && golfball.GetY() < 10.0) { g.DrawString("You're on the green", font, brush, 100, 30); } else { g.DrawString("You missed", font, brush, 100, 30); } } } static void Main() { Application.Run(new GolfGame2()); } } PK ZC2)ж552Code/Csharp_Code/Chapter05_Projectile/GolfGame3.csusing System; using System.Windows.Forms; using System.Drawing; public class GolfGame3 : Form { private Label vxLabel; private Label vyLabel; private Label vzLabel; private Label distanceLabel; private Label axesLabel; private Label massLabel; private Label areaLabel; private Label cdLabel; private Label densityLabel; private Label windVxLabel; private Label windVyLabel; private TextBox vxTextBox; private TextBox vyTextBox; private TextBox vzTextBox; private TextBox distanceTextBox; private TextBox massTextBox; private TextBox areaTextBox; private TextBox cdTextBox; private TextBox densityTextBox; private TextBox windVxTextBox; private TextBox windVyTextBox; private ComboBox axesComboBox; private Button fireButton; private Button resetButton; private Panel drawingPanel; // This field is for the images used in the game. private Image golferIcon; private Image flagIcon; // The Timer is used to control the execution speed // of the game. private Timer gameTimer; // The golf ball is a WindProjectile private WindProjectile golfball; // The player can control the distance to the hole. private double distanceToHole; public GolfGame3() { // Create a WindProjectile object with default values // so the display can be updated the first time. golfball = new WindProjectile(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0459, 0.001432, 0.5, 1.225, 0.0, 0.0); // Set up images golferIcon = Image.FromFile("Golfer.jpg"); flagIcon = Image.FromFile("Hole_Cartoon.jpg"); // Initialize the distanceToHole field. distanceToHole = 200.0; // Create a Timer object that will be used // to slow the action down. gameTimer = new Timer(); gameTimer.Interval = 50; // delay in milliseconds. gameTimer.Tick += new EventHandler(ActionPerformed); // Create some Labels vxLabel = new Label(); vxLabel.Text = "Initial x-velocity, m/s"; vxLabel.Font = new Font(vxLabel.Font, FontStyle.Bold); vxLabel.Top = 50; vxLabel.Left = 10; vxLabel.Width = 130; vyLabel = new Label(); vyLabel.Text = "Initial y-velocity, m/s"; vyLabel.Font = new Font(vyLabel.Font, FontStyle.Bold); vyLabel.Top = 80; vyLabel.Left = 10; vyLabel.Width = 130; vzLabel = new Label(); vzLabel.Text = "Initial z-velocity, m/s"; vzLabel.Font = new Font(vzLabel.Font, FontStyle.Bold); vzLabel.Top = 110; vzLabel.Left = 10; vzLabel.Width = 130; distanceLabel = new Label(); distanceLabel.Text = "Distance to hole, m"; distanceLabel.Font = new Font(distanceLabel.Font, FontStyle.Bold); distanceLabel.Top = 140; distanceLabel.Left = 10; distanceLabel.Width = 120; massLabel = new Label(); massLabel.Text = "mass, kg"; massLabel.Font = new Font(massLabel.Font, FontStyle.Bold); massLabel.Top = 50; massLabel.Left = 210; massLabel.Width = 110; areaLabel = new Label(); areaLabel.Text = "area, m^2"; areaLabel.Font = new Font(areaLabel.Font, FontStyle.Bold); areaLabel.Top = 80; areaLabel.Left = 210; areaLabel.Width = 110; cdLabel = new Label(); cdLabel.Text = "drag coefficient"; cdLabel.Font = new Font(cdLabel.Font, FontStyle.Bold); cdLabel.Top = 110; cdLabel.Left = 210; cdLabel.Width = 110; densityLabel = new Label(); densityLabel.Text = "density, kg/m^3"; densityLabel.Font = new Font(densityLabel.Font, FontStyle.Bold); densityLabel.Top = 140; densityLabel.Left = 210; densityLabel.Width = 110; axesLabel = new Label(); axesLabel.Text = "View axes"; axesLabel.Font = new Font(axesLabel.Font, FontStyle.Bold); axesLabel.Top = 170; axesLabel.Left = 10; axesLabel.Width = 70; windVxLabel = new Label(); windVxLabel.Text = "Wind x-velocity, m/s"; windVxLabel.Font = new Font(windVxLabel.Font, FontStyle.Bold); windVxLabel.Top = 170; windVxLabel.Left = 210; windVxLabel.Width = 120; windVyLabel = new Label(); windVyLabel.Text = "Wind y-velocity, m/s"; windVyLabel.Font = new Font(windVyLabel.Font, FontStyle.Bold); windVyLabel.Top = 200; windVyLabel.Left = 210; windVyLabel.Width = 120; // Create TextBox objects to display the inputs. vxTextBox = new TextBox(); vxTextBox.Width = 50; vxTextBox.Text = "31.0"; vxTextBox.AutoSize = true; vxTextBox.Top = vxLabel.Top; vxTextBox.Left = 150; vyTextBox = new TextBox(); vyTextBox.Width = 50; vyTextBox.Text = "0.0"; vyTextBox.AutoSize = true; vyTextBox.Top = vyLabel.Top; vyTextBox.Left = 150; vzTextBox = new TextBox(); vzTextBox.Width = 50; vzTextBox.Text = "35.0"; vzTextBox.AutoSize = true; vzTextBox.Top = vzLabel.Top; vzTextBox.Left = 150; distanceTextBox = new TextBox(); distanceTextBox.Width = 50; distanceTextBox.Text = "200.0"; distanceTextBox.AutoSize = true; distanceTextBox.Top = distanceLabel.Top; distanceTextBox.Left = 150; massTextBox = new TextBox(); massTextBox.Width = 60; massTextBox.Text = "0.0459"; massTextBox.AutoSize = true; massTextBox.Top = massLabel.Top; massTextBox.Left = 330; areaTextBox = new TextBox(); areaTextBox.Width = 60; areaTextBox.Text = "0.001432"; areaTextBox.AutoSize = true; areaTextBox.Top = areaLabel.Top; areaTextBox.Left = 330; cdTextBox = new TextBox(); cdTextBox.Width = 60; cdTextBox.Text = "0.25"; cdTextBox.AutoSize = true; cdTextBox.Top = cdLabel.Top; cdTextBox.Left = 330; densityTextBox = new TextBox(); densityTextBox.Width = 60; densityTextBox.Text = "1.225"; densityTextBox.AutoSize = true; densityTextBox.Top = densityLabel.Top; densityTextBox.Left = 330; windVxTextBox = new TextBox(); windVxTextBox.Width = 50; windVxTextBox.Text = "10.0"; windVxTextBox.AutoSize = true; windVxTextBox.Top = windVxLabel.Top; windVxTextBox.Left = 330; windVyTextBox = new TextBox(); windVyTextBox.Width = 50; windVyTextBox.Text = "0.0"; windVyTextBox.AutoSize = true; windVyTextBox.Top = windVyLabel.Top; windVyTextBox.Left = 330; // Create a ComboBox to select the view axes. axesComboBox = new ComboBox(); axesComboBox.Items.Add("XZ"); axesComboBox.Items.Add("XY"); axesComboBox.SelectedIndex = 0; axesComboBox.Left = 80; axesComboBox.Top = axesLabel.Top; // Create Button objects int buttonHeight = 30; int buttonWidth = 50; int buttonLeft = 20; fireButton = new Button(); fireButton.Text = "Fire"; fireButton.Height = buttonHeight; fireButton.Width = buttonWidth; fireButton.Top = 200; fireButton.Left = buttonLeft; fireButton.Click += new EventHandler(FireButtonClicked); resetButton = new Button(); resetButton.Text = "Reset"; resetButton.Height = buttonHeight; resetButton.Width = buttonWidth; resetButton.Top = 250; resetButton.Left = buttonLeft; resetButton.Click += new EventHandler(ResetButtonClicked); // Create a drawing panel. drawingPanel = new Panel(); drawingPanel.Width = 501; drawingPanel.Height = 201; drawingPanel.Left = 20; drawingPanel.Top = 300; drawingPanel.BorderStyle = BorderStyle.FixedSingle; // Add the GUI components to the Form this.Controls.Add(vxLabel); this.Controls.Add(vyLabel); this.Controls.Add(vzLabel); this.Controls.Add(distanceLabel); this.Controls.Add(axesLabel); this.Controls.Add(massLabel); this.Controls.Add(areaLabel); this.Controls.Add(cdLabel); this.Controls.Add(densityLabel); this.Controls.Add(windVxLabel); this.Controls.Add(windVyLabel); this.Controls.Add(vxTextBox); this.Controls.Add(vyTextBox); this.Controls.Add(vzTextBox); this.Controls.Add(distanceTextBox); this.Controls.Add(massTextBox); this.Controls.Add(areaTextBox); this.Controls.Add(cdTextBox); this.Controls.Add(densityTextBox); this.Controls.Add(windVxTextBox); this.Controls.Add(windVyTextBox); this.Controls.Add(axesComboBox); this.Controls.Add(fireButton); this.Controls.Add(resetButton); this.Controls.Add(drawingPanel); // Set the size and title of the form this.Width = 600; this.Height = 550; this.Text = "Golf Game version 3"; // Center the form on the screen and make // it visible. this.StartPosition = FormStartPosition.CenterScreen; this.Visible = true; // Update the GUI display UpdateDisplay(); } // Event handling method for the "Fire" button public void FireButtonClicked(object source, EventArgs e) { // Get the initial values from the textfield double vx0 = Convert.ToDouble(vxTextBox.Text); double vy0 = Convert.ToDouble(vyTextBox.Text); double vz0 = Convert.ToDouble(vzTextBox.Text); distanceToHole = Convert.ToDouble(distanceTextBox.Text); double mass = Convert.ToDouble(massTextBox.Text); double area = Convert.ToDouble(areaTextBox.Text); double cd = Convert.ToDouble(cdTextBox.Text); double density = Convert.ToDouble(densityTextBox.Text); double windVx = Convert.ToDouble(windVxTextBox.Text); double windVy = Convert.ToDouble(windVyTextBox.Text); // Create a WindProjectile object representing the golf ball. golfball = new WindProjectile(0.0, 0.0, 0.0, vx0, vy0, vz0, 0.0, mass, area, density, cd, windVx, windVy); // Update the display UpdateDisplay(); // Fire the golf ball using a Timer object // to slow down the action. gameTimer.Start(); } // Event handling method for the "Reset" button public void ResetButtonClicked(object source, EventArgs e) { // stop the timer. gameTimer.Stop(); // Reset the time, location, and velocity of ball; golfball.S = 0.0; // time golfball.SetQ(0.0,0); // vx0 golfball.SetQ(0.0,1); // x0 golfball.SetQ(0.0,2); // vy0 golfball.SetQ(0.0,3); // y0 golfball.SetQ(0.0,4); // vz0 golfball.SetQ(0.0,5); // z0 // Reset the distance to hole. distanceToHole = Convert.ToDouble(distanceTextBox.Text); // Update the display. UpdateDisplay(); } // This method redraws the GUI display. private void UpdateDisplay() { Graphics g = drawingPanel.CreateGraphics(); int width = drawingPanel.Width - 1; int height = drawingPanel.Height - 1; // Clear the current display. // g.Clear(drawingPanel.BackColor); g.Clear(Color.White); // Update the position of the golfball on the screen. SolidBrush brush = new SolidBrush(Color.Black); Pen blackPen = new Pen(Color.Black, 1); // Draw picture based on whether the XZ or // XY axes are selected. string axes = (string)axesComboBox.SelectedItem; if ( String.Equals(axes, "XZ") ) { // Draw the golfer. int zLocation = height - 50; g.DrawImage(golferIcon, 0, zLocation, 34, 50); // Draw the flag zLocation = height - 62; g.DrawImage(flagIcon, (int)(2.0*distanceToHole), zLocation, 55, 62); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX() + 14); int zPosition = (int)(height - 5 - 2.0*golfball.GetZ()); g.FillEllipse(brush, xPosition, zPosition, 5, 5); } else { // Draw location of green. g.DrawEllipse(blackPen, (int)(2.0*distanceToHole - 20), 80, 40, 40); g.FillEllipse(brush, (int)(2.0*distanceToHole - 4), 96, 8, 8); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX()); int yPosition = (int)(100 - 2 - 2.0*golfball.GetY()); g.FillEllipse(brush, xPosition, yPosition, 5, 5); } // Clean up the Graphics object. g.Dispose(); } // This method is called by the Timer every 0.05 seconds. public void ActionPerformed(object source, EventArgs e) { // Update the time and compute the new position // of the golfball. double timeIncrement = 0.07; golfball.UpdateLocationAndVelocity(timeIncrement); // Update the display UpdateDisplay(); // Access the Graphics object of the drawing panel. Graphics g = drawingPanel.CreateGraphics(); // When the golfball hits the ground, stop the simulation // and see where ball has landed. if ( golfball.GetZ() <= 0.0 ) { Console.WriteLine("time="+(float)golfball.GetTime()+ " x="+(float)golfball.GetX()+ " y="+(float)golfball.GetY()+" z="+(float)golfball.GetZ()); // Stop the simulation gameTimer.Stop(); // Determine if ball is on the green. SolidBrush brush = new SolidBrush(Color.Black); Font font = new Font("Arial", 12); if ( golfball.GetX() > distanceToHole - 10.0 && golfball.GetX() < distanceToHole + 10.0 && golfball.GetY() < 10.0) { g.DrawString("You're on the green", font, brush, 100, 30); } else { g.DrawString("You missed", font, brush, 100, 30); } } } static void Main() { Application.Run(new GolfGame3()); } } PK `C2'˶BB2Code/Csharp_Code/Chapter05_Projectile/GolfGame4.csusing System; using System.Windows.Forms; using System.Drawing; public class GolfGame4 : Form { private Label vxLabel; private Label vyLabel; private Label vzLabel; private Label distanceLabel; private Label axesLabel; private Label massLabel; private Label areaLabel; private Label cdLabel; private Label densityLabel; private Label windVxLabel; private Label windVyLabel; private Label rxLabel; private Label ryLabel; private Label rzLabel; private Label omegaLabel; private Label radiusLabel; private Label spinAxisLabel; private TextBox vxTextBox; private TextBox vyTextBox; private TextBox vzTextBox; private TextBox distanceTextBox; private TextBox massTextBox; private TextBox areaTextBox; private TextBox cdTextBox; private TextBox densityTextBox; private TextBox windVxTextBox; private TextBox windVyTextBox; private TextBox rxTextBox; private TextBox ryTextBox; private TextBox rzTextBox; private TextBox omegaTextBox; private TextBox radiusTextBox; private ComboBox axesComboBox; private Button fireButton; private Button resetButton; private Panel drawingPanel; // This field is for the images used in the game. private Image golferIcon; private Image flagIcon; // The Timer is used to control the execution speed // of the game. private Timer gameTimer; // The golf ball is a SpinProjectile private SpinProjectile golfball; // The player can control the distance to the hole. private double distanceToHole; public GolfGame4() { // Create a SpinProjectile object with default values // so the display can be updated the first time. golfball = new SpinProjectile(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0459, 0.001432, 0.5, 1.225, 0.0, 0.0, 0.0, 1.0, 0.0, 300.0, 0.02135); // Set up images golferIcon = Image.FromFile("Golfer.jpg"); flagIcon = Image.FromFile("Hole_Cartoon.jpg"); // Initialize the distanceToHole field. distanceToHole = 200.0; // Create a Timer object that will be used // to slow the action down. gameTimer = new Timer(); gameTimer.Interval = 50; // delay in milliseconds. gameTimer.Tick += new EventHandler(ActionPerformed); // Create some Labels vxLabel = new Label(); vxLabel.Text = "Initial x-velocity, m/s"; vxLabel.Font = new Font(vxLabel.Font, FontStyle.Bold); vxLabel.Top = 50; vxLabel.Left = 10; vxLabel.Width = 130; vyLabel = new Label(); vyLabel.Text = "Initial y-velocity, m/s"; vyLabel.Font = new Font(vyLabel.Font, FontStyle.Bold); vyLabel.Top = 80; vyLabel.Left = 10; vyLabel.Width = 130; vzLabel = new Label(); vzLabel.Text = "Initial z-velocity, m/s"; vzLabel.Font = new Font(vzLabel.Font, FontStyle.Bold); vzLabel.Top = 110; vzLabel.Left = 10; vzLabel.Width = 130; distanceLabel = new Label(); distanceLabel.Text = "Distance to hole, m"; distanceLabel.Font = new Font(distanceLabel.Font, FontStyle.Bold); distanceLabel.Top = 140; distanceLabel.Left = 10; distanceLabel.Width = 120; massLabel = new Label(); massLabel.Text = "mass, kg"; massLabel.Font = new Font(massLabel.Font, FontStyle.Bold); massLabel.Top = 50; massLabel.Left = 210; massLabel.Width = 110; areaLabel = new Label(); areaLabel.Text = "area, m^2"; areaLabel.Font = new Font(areaLabel.Font, FontStyle.Bold); areaLabel.Top = 80; areaLabel.Left = 210; areaLabel.Width = 110; cdLabel = new Label(); cdLabel.Text = "drag coefficient"; cdLabel.Font = new Font(cdLabel.Font, FontStyle.Bold); cdLabel.Top = 110; cdLabel.Left = 210; cdLabel.Width = 110; densityLabel = new Label(); densityLabel.Text = "density, kg/m^3"; densityLabel.Font = new Font(densityLabel.Font, FontStyle.Bold); densityLabel.Top = 140; densityLabel.Left = 210; densityLabel.Width = 110; axesLabel = new Label(); axesLabel.Text = "View axes"; axesLabel.Font = new Font(axesLabel.Font, FontStyle.Bold); axesLabel.Top = 170; axesLabel.Left = 10; axesLabel.Width = 70; windVxLabel = new Label(); windVxLabel.Text = "Wind x-velocity, m/s"; windVxLabel.Font = new Font(windVxLabel.Font, FontStyle.Bold); windVxLabel.Top = 170; windVxLabel.Left = 210; windVxLabel.Width = 120; windVyLabel = new Label(); windVyLabel.Text = "Wind y-velocity, m/s"; windVyLabel.Font = new Font(windVyLabel.Font, FontStyle.Bold); windVyLabel.Top = 200; windVyLabel.Left = 210; windVyLabel.Width = 120; omegaLabel = new Label(); omegaLabel.Text = "Angular velocity, rad/s"; omegaLabel.Font = new Font(omegaLabel.Font, FontStyle.Bold); omegaLabel.Top = 50; omegaLabel.Left = 400; omegaLabel.Width = 120; radiusLabel = new Label(); radiusLabel.Text = "Sphere radius, m"; radiusLabel.Font = new Font(radiusLabel.Font, FontStyle.Bold); radiusLabel.Top = 80; radiusLabel.Left = 400; radiusLabel.Width = 120; spinAxisLabel = new Label(); spinAxisLabel.Text = "Spin Axes"; spinAxisLabel.Font = new Font(spinAxisLabel.Font, FontStyle.Bold); spinAxisLabel.Top = 110; spinAxisLabel.Left = 400; spinAxisLabel.Width = 120; rxLabel = new Label(); rxLabel.Text = "rx"; rxLabel.Font = new Font(rxLabel.Font, FontStyle.Bold); rxLabel.Top = 140; rxLabel.Left = 400; rxLabel.Width = 50; ryLabel = new Label(); ryLabel.Text = "ry"; ryLabel.Font = new Font(ryLabel.Font, FontStyle.Bold); ryLabel.Top = 170; ryLabel.Left = 400; ryLabel.Width = 50; rzLabel = new Label(); rzLabel.Text = "rz"; rzLabel.Font = new Font(rzLabel.Font, FontStyle.Bold); rzLabel.Top = 200; rzLabel.Left = 400; rzLabel.Width = 50; // Create TextBox objects to display the inputs. vxTextBox = new TextBox(); vxTextBox.Width = 50; vxTextBox.Text = "31.0"; vxTextBox.AutoSize = true; vxTextBox.Top = vxLabel.Top; vxTextBox.Left = 150; vyTextBox = new TextBox(); vyTextBox.Width = 50; vyTextBox.Text = "0.0"; vyTextBox.AutoSize = true; vyTextBox.Top = vyLabel.Top; vyTextBox.Left = 150; vzTextBox = new TextBox(); vzTextBox.Width = 50; vzTextBox.Text = "35.0"; vzTextBox.AutoSize = true; vzTextBox.Top = vzLabel.Top; vzTextBox.Left = 150; distanceTextBox = new TextBox(); distanceTextBox.Width = 50; distanceTextBox.Text = "200.0"; distanceTextBox.AutoSize = true; distanceTextBox.Top = distanceLabel.Top; distanceTextBox.Left = 150; massTextBox = new TextBox(); massTextBox.Width = 60; massTextBox.Text = "0.0459"; massTextBox.AutoSize = true; massTextBox.Top = massLabel.Top; massTextBox.Left = 330; areaTextBox = new TextBox(); areaTextBox.Width = 60; areaTextBox.Text = "0.001432"; areaTextBox.AutoSize = true; areaTextBox.Top = areaLabel.Top; areaTextBox.Left = 330; cdTextBox = new TextBox(); cdTextBox.Width = 60; cdTextBox.Text = "0.25"; cdTextBox.AutoSize = true; cdTextBox.Top = cdLabel.Top; cdTextBox.Left = 330; densityTextBox = new TextBox(); densityTextBox.Width = 60; densityTextBox.Text = "1.225"; densityTextBox.AutoSize = true; densityTextBox.Top = densityLabel.Top; densityTextBox.Left = 330; windVxTextBox = new TextBox(); windVxTextBox.Width = 50; windVxTextBox.Text = "10.0"; windVxTextBox.AutoSize = true; windVxTextBox.Top = windVxLabel.Top; windVxTextBox.Left = 330; windVyTextBox = new TextBox(); windVyTextBox.Width = 50; windVyTextBox.Text = "0.0"; windVyTextBox.AutoSize = true; windVyTextBox.Top = windVyLabel.Top; windVyTextBox.Left = 330; omegaTextBox = new TextBox(); omegaTextBox.Width = 60; omegaTextBox.Text = "300.0"; omegaTextBox.AutoSize = true; omegaTextBox.Top = omegaLabel.Top; omegaTextBox.Left = 530; radiusTextBox = new TextBox(); radiusTextBox.Width = 60; radiusTextBox.Text = "0.02135"; radiusTextBox.AutoSize = true; radiusTextBox.Top = radiusLabel.Top; radiusTextBox.Left = 530; rxTextBox = new TextBox(); rxTextBox.Width = 60; rxTextBox.Text = "0.0"; rxTextBox.AutoSize = true; rxTextBox.Top = rxLabel.Top; rxTextBox.Left = 530; ryTextBox = new TextBox(); ryTextBox.Width = 50; ryTextBox.Text = "1.0"; ryTextBox.AutoSize = true; ryTextBox.Top = ryLabel.Top; ryTextBox.Left = 530; rzTextBox = new TextBox(); rzTextBox.Width = 50; rzTextBox.Text = "0.0"; rzTextBox.AutoSize = true; rzTextBox.Top = rzLabel.Top; rzTextBox.Left = 530; // Create a ComboBox to select the view axes. axesComboBox = new ComboBox(); axesComboBox.Items.Add("XZ"); axesComboBox.Items.Add("XY"); axesComboBox.SelectedIndex = 0; axesComboBox.Left = 80; axesComboBox.Top = axesLabel.Top; // Create Button objects int buttonHeight = 30; int buttonWidth = 50; int buttonLeft = 20; fireButton = new Button(); fireButton.Text = "Fire"; fireButton.Height = buttonHeight; fireButton.Width = buttonWidth; fireButton.Top = 200; fireButton.Left = buttonLeft; fireButton.Click += new EventHandler(FireButtonClicked); resetButton = new Button(); resetButton.Text = "Reset"; resetButton.Height = buttonHeight; resetButton.Width = buttonWidth; resetButton.Top = 250; resetButton.Left = buttonLeft; resetButton.Click += new EventHandler(ResetButtonClicked); // Create a drawing panel. drawingPanel = new Panel(); drawingPanel.Width = 501; drawingPanel.Height = 201; drawingPanel.Left = 20; drawingPanel.Top = 300; drawingPanel.BorderStyle = BorderStyle.FixedSingle; // Add the GUI components to the Form this.Controls.Add(vxLabel); this.Controls.Add(vyLabel); this.Controls.Add(vzLabel); this.Controls.Add(distanceLabel); this.Controls.Add(axesLabel); this.Controls.Add(massLabel); this.Controls.Add(areaLabel); this.Controls.Add(cdLabel); this.Controls.Add(densityLabel); this.Controls.Add(windVxLabel); this.Controls.Add(windVyLabel); this.Controls.Add(omegaLabel); this.Controls.Add(radiusLabel); this.Controls.Add(spinAxisLabel); this.Controls.Add(rxLabel); this.Controls.Add(ryLabel); this.Controls.Add(rzLabel); this.Controls.Add(vxTextBox); this.Controls.Add(vyTextBox); this.Controls.Add(vzTextBox); this.Controls.Add(distanceTextBox); this.Controls.Add(massTextBox); this.Controls.Add(areaTextBox); this.Controls.Add(cdTextBox); this.Controls.Add(densityTextBox); this.Controls.Add(windVxTextBox); this.Controls.Add(windVyTextBox); this.Controls.Add(omegaTextBox); this.Controls.Add(radiusTextBox); this.Controls.Add(rxTextBox); this.Controls.Add(ryTextBox); this.Controls.Add(rzTextBox); this.Controls.Add(axesComboBox); this.Controls.Add(fireButton); this.Controls.Add(resetButton); this.Controls.Add(drawingPanel); // Set the size and title of the form this.Width = 620; this.Height = 550; this.Text = "Golf Game version 4"; // Center the form on the screen and make // it visible. this.StartPosition = FormStartPosition.CenterScreen; this.Visible = true; // Update the GUI display UpdateDisplay(); } // Event handling method for the "Fire" button public void FireButtonClicked(object source, EventArgs e) { // Get the initial values from the textfield double vx0 = Convert.ToDouble(vxTextBox.Text); double vy0 = Convert.ToDouble(vyTextBox.Text); double vz0 = Convert.ToDouble(vzTextBox.Text); distanceToHole = Convert.ToDouble(distanceTextBox.Text); double mass = Convert.ToDouble(massTextBox.Text); double area = Convert.ToDouble(areaTextBox.Text); double cd = Convert.ToDouble(cdTextBox.Text); double density = Convert.ToDouble(densityTextBox.Text); double windVx = Convert.ToDouble(windVxTextBox.Text); double windVy = Convert.ToDouble(windVyTextBox.Text); double rx = Convert.ToDouble(rxTextBox.Text); double ry = Convert.ToDouble(ryTextBox.Text); double rz = Convert.ToDouble(rzTextBox.Text); double omega = Convert.ToDouble(omegaTextBox.Text); double radius = Convert.ToDouble(radiusTextBox.Text); // Create a SpinProjectile object representing the golf ball. golfball = new SpinProjectile(0.0, 0.0, 0.0, vx0, vy0, vz0, 0.0, mass, area, density, cd, windVx, windVy, rx, ry, rz, omega, radius); // Update the display UpdateDisplay(); // Fire the golf ball using a Timer object // to slow down the action. gameTimer.Start(); } // Event handling method for the "Reset" button public void ResetButtonClicked(object source, EventArgs e) { // stop the timer. gameTimer.Stop(); // Reset the time, location, and velocity of ball; golfball.S = 0.0; // time golfball.SetQ(0.0,0); // vx0 golfball.SetQ(0.0,1); // x0 golfball.SetQ(0.0,2); // vy0 golfball.SetQ(0.0,3); // y0 golfball.SetQ(0.0,4); // vz0 golfball.SetQ(0.0,5); // z0 // Reset the distance to hole. distanceToHole = Convert.ToDouble(distanceTextBox.Text); // Update the display. UpdateDisplay(); } // This method redraws the GUI display. private void UpdateDisplay() { Graphics g = drawingPanel.CreateGraphics(); int width = drawingPanel.Width - 1; int height = drawingPanel.Height - 1; // Clear the current display. // g.Clear(drawingPanel.BackColor); g.Clear(Color.White); // Update the position of the golfball on the screen. SolidBrush brush = new SolidBrush(Color.Black); Pen blackPen = new Pen(Color.Black, 1); // Draw picture based on whether the XZ or // XY axes are selected. string axes = (string)axesComboBox.SelectedItem; if ( String.Equals(axes, "XZ") ) { // Draw the golfer. int zLocation = height - 50; g.DrawImage(golferIcon, 0, zLocation, 34, 50); // Draw the flag zLocation = height - 62; g.DrawImage(flagIcon, (int)(2.0*distanceToHole), zLocation, 55, 62); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX() + 14); int zPosition = (int)(height - 5 - 2.0*golfball.GetZ()); g.FillEllipse(brush, xPosition, zPosition, 5, 5); } else { // Draw location of green. g.DrawEllipse(blackPen, (int)(2.0*distanceToHole - 20), 80, 40, 40); g.FillEllipse(brush, (int)(2.0*distanceToHole - 4), 96, 8, 8); // Update the position of the golfball // on the screen. int xPosition = (int)(2.0*golfball.GetX()); int yPosition = (int)(100 - 2 - 2.0*golfball.GetY()); g.FillEllipse(brush, xPosition, yPosition, 5, 5); } // Clean up the Graphics object. g.Dispose(); } // This method is called by the Timer every 0.05 seconds. public void ActionPerformed(object source, EventArgs e) { // Update the time and compute the new position // of the golfball. double timeIncrement = 0.07; golfball.UpdateLocationAndVelocity(timeIncrement); // Update the display UpdateDisplay(); // Access the Graphics object of the drawing panel. Graphics g = drawingPanel.CreateGraphics(); // When the golfball hits the ground, stop the simulation // and see where ball has landed. if ( golfball.GetZ() <= 0.0 ) { Console.WriteLine("time="+(float)golfball.GetTime()+ " x="+(float)golfball.GetX()+ " y="+(float)golfball.GetY()+" z="+(float)golfball.GetZ()); // Stop the simulation gameTimer.Stop(); // Determine if ball is on the green. SolidBrush brush = new SolidBrush(Color.Black); Font font = new Font("Arial", 12); if ( golfball.GetX() > distanceToHole - 10.0 && golfball.GetX() < distanceToHole + 10.0 && golfball.GetY() < 10.0) { g.DrawString("You're on the green", font, brush, 100, 30); } else { g.DrawString("You missed", font, brush, 100, 30); } } } static void Main() { Application.Run(new GolfGame4()); } } PK 1P72..6Code/Csharp_Code/Chapter05_Projectile/Hole_Cartoon.jpgJFIF``LEAD Technologies Inc. V1.01  }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzw!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ? ( ~~:σ>|AQYA.:cm^ak}k%GZj5S4UIcutrqOTdڻ_wM՟MOm_?xAsmor蚭 [RDKʯEFR t7$e5}$W%-/+vҔe\[ T@P@P@P@v{ w? ɵ _7S҄ւF|+c_ڳ1$o2#eUV~p|eXghЄvwWvgfڼi{VM~{#{ >MuZZKk;vc(m^Bx}1x/0XL6QBPxoa{ro}GBV哅}5c<~!oS>ʸkNQt& kW_+[,σ~Fy[o%bJXqoi*OKۂm("CV*uSJϖW^oT^]]CW?hcýVHuMK@T06Ge2yznn&.|)9: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jFSa+[[W;'OkuI/Kc54yR <-x%ӿEo.-6smWYӾ֜EE?~[bu 6$I%I$J+umuV ִ\9yYιb}Z7=8KOj=]ؽ'm=;rr\&\,7l3v 1CY3̌"ڻoSn];{W_f6"SM K'QT'sOG/&|>y?bI%ssdևsv &,n~ūgYIՋQ%Pư7q6Yloձޥ@L\]6d<e$J6%$I)I$JRI$I$$I)b8<3fuiV$4Kte(%ќ}21+uݽ3e8՞ [dtϭR @mܴ9ϸ V! [Xh?0u̖a^s,āk]wqtk.sum?.t؛~ٗhcþ1D]}?F$ 01)/&2P9FQK}\%wpUkmng~Aն'亷nϏ^'_bx|8cghCG7r饧7cvbv %Z*ׇ~~'3tW H 9xb z=k)\I?+c< c6?u`?r8~/? wW~}pk]Ց/o dB3˝/q ̣5el΃/$:}oC=xrW쿭'Qsc͎#гb^wO뿠x㏃ y.ixy땿,:SW{IƑū0-12_+^~^+O2 װuՐ}WGv7)7[o$O|Wܗx`ls/>/ۆSSGg5I">Ӈ.ܺp>PW;SŨ kAmJ?1λaU[~ozbJHfݿGpx7ӷM[6~{QSeigul?% _FQҾ=WU*;suN1iGtWi+'.aM4XUm,` h5i$PK 2y+,Code/Csharp_Code/Chapter05_Projectile/ODE.csusing System; public abstract class ODE { // Declare fields used by the class private int numEqns; // number of equations to solve private double[] q; // array of dependent variables private double s; // independent variable // Constructor public ODE(int numEqns) { this.numEqns = numEqns; q = new double[numEqns]; } // These properties access the value of the numEqns // and s fields. public int NumEqns { get { return numEqns; } } public double S { get { return s; } set { s = value; } } // This method returns the entire q[] array. public double GetQ(int index) { return q[index]; } public void SetQ(double value, int index) { q[index] = value; return; } public double[] GetAllQ() { return q; } // This method returns the right-hand side of the // ODEs. It is declared abstract to force subclasses // to implement their own version of the method. public abstract double[] GetRightHandSide(double s, double[] q,double[] deltaQ, double ds, double qScale); } PK 2͞FF2Code/Csharp_Code/Chapter05_Projectile/ODESolver.csusing System; public class ODESolver { // Fourth-order Runge-Kutta ODE solver. public static void RungeKutta4(ODE ode, double ds) { // Define some convenience variables to make the // code more readable int j; int numEqns = ode.NumEqns; double s; double[] q; double[] dq1 = new double[numEqns]; double[] dq2 = new double[numEqns]; double[] dq3 = new double[numEqns]; double[] dq4 = new double[numEqns]; // Retrieve the current values of the dependent // and independent variables. s = ode.S; q = ode.GetAllQ(); // Compute the four Runge-Kutta steps, The return // value of getRightHandSide method is an array of // delta-q values for each of the four steps. dq1 = ode.GetRightHandSide(s, q, q, ds, 0.0); dq2 = ode.GetRightHandSide(s+0.5*ds, q, dq1, ds, 0.5); dq3 = ode.GetRightHandSide(s+0.5*ds, q, dq2, ds, 0.5); dq4 = ode.GetRightHandSide(s+ds, q, dq3, ds, 1.0); // Update the dependent and independent variable values // at the new dependent variable location and store the // values in the ODE object arrays. ode.S = s + ds; for(j=0; j