NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation Class Reference

Simulation of a regular double pendulum. More...

Inheritance diagram for NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation:
NewGamePhysics.PhysicalElements.DoublePendulumSimulationBase

List of all members.

Public Member Functions

 DoubleRegularPendulumSimulation (Vector2 origin, double l1, double m1, double l2, double m2, double g, RotationalFrictionType f)
 Constructor for animated double pendulum using a standard stepsize.
override void SetInitialConditionsAtRest ()
 Resets the initial conditions (angles and rotational speeds) for the pendulum simulation to a be at rest.
override Vector2[] GetPosition ()
 Calculate pedulum positions relative.
override Vector2[] GetPosition (Vector2 screenOrigin, double screenScale)
 Calculate pedulum positions relative to a screen origin and scale.
override double[] GetSize ()
 Calculate the 2 sizes of each bar .
override double[] GetSize (double scale)
 Calculate the 2 sizes of each bar with the scale applied.
override double GetEnergy ()
 Calculates the current total energy of the system.

Detailed Description

Simulation of a regular double pendulum.

Definition at line 23 of file DoubleRegularPendulumSimulation.cs.


Constructor & Destructor Documentation

NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation.DoubleRegularPendulumSimulation ( Vector2  origin,
double  l1,
double  m1,
double  l2,
double  m2,
double  g,
RotationalFrictionType  f 
)

Constructor for animated double pendulum using a standard stepsize.

Parameters:
origin Position or anchor of pendulum.
l1 Length of the first rod.
m1 Mass of the first pendulum component.
l2 Length of the second rod.
m2 Mass of the second pendulum component
g The gravitational acceleration to apply.
f The frictional model to use for the hinges.

Definition at line 35 of file DoubleRegularPendulumSimulation.cs.

00043         {
00044             // Origin
00045             this.origin = origin;
00046 
00047             // Time and stepsize
00048             this.T = 0.0;
00049             this.H = 0.01;
00050 
00051             // Construct pendulum
00052             this.PendulumAcceleration =
00053                 (ISecondDerivative)new DoubleRegularPendulumAcceleration(l1, m1, l2, m2, g);
00054             
00055             // Reset initial conditions
00056             this.theta = new VectorN(2);
00057             this.omega = new VectorN(2);
00058             this.SetInitialConditionsAtRest();
00059 
00060             // Initialize friction model
00061             this.FrictionModel = new RotationalFrictionModel(f);
00062         }


Member Function Documentation

override double NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation.GetEnergy (  )  [virtual]

Calculates the current total energy of the system.

Returns:
The energy value.

Implements NewGamePhysics.PhysicalElements.DoublePendulumSimulationBase.

Definition at line 172 of file DoubleRegularPendulumSimulation.cs.

00173         {
00174             DoubleRegularPendulumAcceleration pendulumAcceleration =
00175                 this.PendulumAcceleration as DoubleRegularPendulumAcceleration;
00176 
00177             double f1 = (1 - Math.Cos(theta[0]));
00178             double f2 = (1 - Math.Cos(theta[1]));
00179             double v = pendulumAcceleration.M1 * pendulumAcceleration.G *  (pendulumAcceleration.L1 * f1) +
00180                        pendulumAcceleration.M2 * pendulumAcceleration.G * ((pendulumAcceleration.L1 * f1) + (pendulumAcceleration.L2 * f2));
00181             double k = 0.5 * (pendulumAcceleration.M1 + pendulumAcceleration.M2) * pendulumAcceleration.L1 * pendulumAcceleration.L1 * omega[0] * omega[0] +
00182                        0.5 * pendulumAcceleration.M2 * pendulumAcceleration.L2 * pendulumAcceleration.L2 * omega[1] * omega[1] +
00183                        pendulumAcceleration.M2 * pendulumAcceleration.L1 * pendulumAcceleration.L2 * Math.Cos(theta[0] - theta[1]) * omega[0] * omega[1];
00184             return (v + k);
00185         }

override Vector2 [] NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation.GetPosition ( Vector2  screenOrigin,
double  screenScale 
) [virtual]

Calculate pedulum positions relative to a screen origin and scale.

Parameters:
screenOrigin Position where to anchor the pendulum.
screenScale The scale of the pendulum (pixels/meter).

/

Returns:
The pendulum positions.

Implements NewGamePhysics.PhysicalElements.DoublePendulumSimulationBase.

Definition at line 119 of file DoubleRegularPendulumSimulation.cs.

00120         {
00121             // Update
00122             Vector2[] pendulumPoints = this.GetPosition();
00123 
00124             // Scale in place
00125             for (int i=0; i<pendulumPoints.Length; i++)
00126             {
00127                 pendulumPoints[i].X = screenOrigin.X + (float)(screenScale * pendulumPoints[i].X);
00128                 pendulumPoints[i].Y = screenOrigin.Y + (float)(screenScale * pendulumPoints[i].Y);
00129             }
00130 
00131             return pendulumPoints;
00132         }

override Vector2 [] NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation.GetPosition (  )  [virtual]

Calculate pedulum positions relative.

Returns:
The pendulum positions.

Implements NewGamePhysics.PhysicalElements.DoublePendulumSimulationBase.

Definition at line 77 of file DoubleRegularPendulumSimulation.cs.

00078         {
00079             // Allocate cache for position state of the pendulum components
00080             Vector2[] pendulumPoints = new Vector2[3];
00081             for (int i = 0; i < pendulumPoints.Length; i++)
00082             {
00083                 pendulumPoints[i] = new Vector2();
00084             }
00085 
00086             // Set angle for top component
00087             double angle = this.theta[0];
00088 
00089             // Set anchor/top of pendulum
00090             pendulumPoints[0].X = this.origin.X;
00091             pendulumPoints[0].Y = this.origin.Y;
00092 
00093             double[] pendulumSize = this.GetSize();
00094 
00095             // Calculate top component positions
00096             pendulumPoints[1].X = 
00097                 (float)(pendulumPoints[0].X + (pendulumSize[0] * Math.Sin(angle)));
00098             pendulumPoints[1].Y = 
00099                 (float)(pendulumPoints[0].Y + (pendulumSize[0] * Math.Cos(angle)));
00100 
00101             // Set angle for bottom component
00102             angle = this.theta[1];
00103 
00104             // Calculate bottom component positions
00105             pendulumPoints[2].X = 
00106                 (float)(pendulumPoints[1].X + (pendulumSize[1] * Math.Sin(angle)));
00107             pendulumPoints[2].Y = 
00108                 (float)(pendulumPoints[1].Y + (pendulumSize[1] * Math.Cos(angle)));
00109 
00110             return pendulumPoints;
00111         }

override double [] NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation.GetSize ( double  scale  )  [virtual]

Calculate the 2 sizes of each bar with the scale applied.

Parameters:
scale The scale factor for the size calculation.
Returns:
Array containing two doubles. First value is for the top bar, second for the bottom bar.

Implements NewGamePhysics.PhysicalElements.DoublePendulumSimulationBase.

Definition at line 157 of file DoubleRegularPendulumSimulation.cs.

00158         {
00159             double[] size = this.GetSize();
00160             for (int i = 0; i < size.Length; i++)
00161             {
00162                 size[i] *= scale;
00163             }
00164 
00165             return size;
00166         }

override double [] NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation.GetSize (  )  [virtual]

Calculate the 2 sizes of each bar .

Returns:
Array containing two doubles. First value is for the top bar, second for the bottom bar.

Implements NewGamePhysics.PhysicalElements.DoublePendulumSimulationBase.

Definition at line 139 of file DoubleRegularPendulumSimulation.cs.

00140         {
00141             DoubleRegularPendulumAcceleration pendulumAcceleration =
00142                 this.PendulumAcceleration as DoubleRegularPendulumAcceleration;
00143 
00144             double[] pendulumSize = new double[2];
00145             pendulumSize[0] = pendulumAcceleration.L1;
00146             pendulumSize[1] = pendulumAcceleration.L2;
00147 
00148             return pendulumSize;
00149         }

override void NewGamePhysics.PhysicalElements.DoubleRegularPendulumSimulation.SetInitialConditionsAtRest (  )  [virtual]

Resets the initial conditions (angles and rotational speeds) for the pendulum simulation to a be at rest.

Implements NewGamePhysics.PhysicalElements.DoublePendulumSimulationBase.

Definition at line 68 of file DoubleRegularPendulumSimulation.cs.

00069         {
00070             SetInitialConditions(0.0, 0.0, 0.0, 0.0);
00071         }


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2