private void StartAnimation( object sender, EventArgs e) { // Invoke ODE solver: ODESolver.Function[] f = new ODESolver.Function[2] { f1, f2 }; double[] result = ODESolver.RungeKutta4( f, xx, time, dt); // Display moving pendulum on screen: Point pt = new Point( 140 + 130 * Math.Sin(result[0]), 20 + 130 * Math.Cos(result[0])); ball.Center = pt; line1.X2 = pt.X; line1.Y2 = pt.Y; // Display theta - time curve on canvasRight: if (time < xMax) { pl.Points.Add(new Point(XNormalize(time) + 10, YNormalize(180 * result[0] / Math.PI))); } // Reset the initial values for next calculation: xx = result; time += dt; if (time > 0 && Math.Abs(result[0]) < 0.01 && Math.Abs(result[1]) < 0.001) { tbDisplay.Text = "Stopped"; CompositionTarget.Rendering -= StartAnimation; } }
void FixedUpdate() { var result = ODESolver.RungeKutta4( new ProjectileODE( new ProjectileODEData(this)), 0); transform.position = result.Position; Properties.Velocity = result.Velocity; if (transform.position.y < 0) { Time.timeScale = 0; Debug.Log(Time.timeSinceLevelLoad); } }
// This method updates the velocity and location // of the projectile using a 4th order Runge-Kutta // solver to integrate the equations of motion. public override void UpdateLocationAndVelocity(double dt) { ODESolver.RungeKutta4(this, dt); }
// This method updates the velocity and position // of the spring using a 4th order Runge-Kutta // solver to integrate the equations of motion. public void UpdatePositionAndVelocity(double dt) { ODESolver.RungeKutta4(this, dt); }