- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/Tests/UnitTestDoubleRegularPendulum.cs

    00001 ﻿
    00002
    00003 namespace Tests
    00004 {
    00005     using System;
    00006     using Microsoft.VisualStudio.TestTools.UnitTesting;
    00007     using Microsoft.Xna.Framework;
    00008     using Microsoft.Xna.Framework.Graphics;
    00009     using NewGamePhysics.Mathematics;
    00010     using NewGamePhysics.Physics;
    00011     using NewGamePhysics.PhysicalElements;
    00012
    00016     [TestClass]
    00017     public class UnitTestDoubleRegularPendulum
    00018     {
    00019         public UnitTestDoubleRegularPendulum()
    00020         {
    00021         }
    00022
    00023         private TestContext testContextInstance;
    00024
    00029         public TestContext TestContext
    00030         {
    00031             get
    00032             {
    00033                 return testContextInstance;
    00034             }
    00035             set
    00036             {
    00037                 testContextInstance = value;
    00038             }
    00039         }
    00040
    00041         [TestMethod]
    00042         public void UnitPendulumAtRest()
    00043         {
    00044             Vector2 origin = new Vector2();
    00045
    00046             // New Pendulum
    00047             DoubleRegularPendulumSimulation pendulum =
    00048                 new DoubleRegularPendulumSimulation(
    00049                     origin,
    00050                     1.0, 1.0, 1.0, 1.0,
    00051                     9.81,
    00052                     RotationalFrictionType.None);
    00053             pendulum.SetInitialConditionsAtRest();
    00054
    00055             AnimatePendulumSimulation(pendulum);
    00056         }
    00057
    00058         [TestMethod]
    00059         public void UnitPendulumInMotionFrictionNone()
    00060         {
    00061             Vector2 origin = new Vector2();
    00062
    00063             // New Pendulum
    00064             DoubleRegularPendulumSimulation pendulum =
    00065                 new DoubleRegularPendulumSimulation(
    00066                     origin,
    00067                     1.0, 1.0, 1.0, 1.0,
    00068                     9.81,
    00069                     RotationalFrictionType.None);
    00070             pendulum.SetInitialConditions(
    00071                     (double)Math.PI * 0.8, (double)0, (double)0, (double)0);
    00072
    00073             AnimatePendulumSimulation(pendulum);
    00074         }
    00075
    00076         [TestMethod]
    00077         public void UnitPendulumInMotionFrictionLinear()
    00078         {
    00079             Vector2 origin = new Vector2();
    00080
    00081             // New Pendulum
    00082             DoubleRegularPendulumSimulation pendulum =
    00083                 new DoubleRegularPendulumSimulation(
    00084                     origin,
    00085                     1.0, 1.0, 1.0, 1.0,
    00086                     9.81,
    00087                     RotationalFrictionType.Linear);
    00088             pendulum.SetInitialConditions(
    00089                     (double)Math.PI * 0.8, (double)0, (double)0, (double)0);
    00090
    00091             AnimatePendulumSimulation(pendulum);
    00092         }
    00093
    00094         [TestMethod]
    00095         public void UnitPendulumInMotionFrictionStribeck()
    00096         {
    00097             Vector2 origin = new Vector2();
    00098
    00099             // New Pendulum
    00100             DoubleRegularPendulumSimulation pendulum =
    00101                 new DoubleRegularPendulumSimulation(
    00102                     origin,
    00103                     1.0, 1.0, 1.0, 1.0,
    00104                     9.81,
    00105                     RotationalFrictionType.Stribeck);
    00106             pendulum.SetInitialConditions(
    00107                     (double)Math.PI * 0.8, (double)0, (double)0, (double)0);
    00108
    00109             AnimatePendulumSimulation(pendulum);
    00110         }
    00111
    00112         [TestMethod]
    00113         public void SmallPendulumInMotionFrictionNone()
    00114         {
    00115             Vector2 origin = new Vector2();
    00116
    00117             // New Pendulum
    00118             DoubleRegularPendulumSimulation pendulum =
    00119                 new DoubleRegularPendulumSimulation(
    00120                     origin,
    00121                     0.1, 1.0, 0.1, 1.0,
    00122                     9.81,
    00123                     RotationalFrictionType.None);
    00124             pendulum.SetInitialConditions(
    00125                     (double)Math.PI * 0.8, (double)0, (double)0, (double)0);
    00126
    00127             AnimatePendulumSimulation(pendulum);
    00128         }
    00129
    00130         private void AnimatePendulumSimulation(DoubleRegularPendulumSimulation pendulum)
    00131         {
    00132             int count = 0;
    00133             for (int i = 0; i < 10; i++)
    00134             {
    00135                 for (int j = 0; j < 1000; j++)
    00136                 {
    00137                     pendulum.Animate();
    00138                     count++;
    00139                 }
    00140
    00141                 double[] angles = pendulum.GetAngle();
    00142                 double[] velocities = pendulum.GetVelocity();
    00143                 double energy = pendulum.GetEnergy();
    00144
    00145                 Console.WriteLine("Iteration {5}: angles = {0} {1}  velocities = {2} {3}  energy = {4}",
    00146                     angles[0], angles[1],
    00147                     velocities[0], velocities[1],
    00148                     energy,
    00149                     count);
    00150             }
    00151         }
    00152     }
    00153 }