public bool CalculateNewCourseAndSpeed(Vector powerVector, double dt, double massKG) { double accn = 0.0; //calculate the acceleration if (PhysicsMaths.CalculateAcceleration(powerVector.Magnitude, massKG, out accn)) { Vector accnVector = new Vector(); accnVector.Magnitude = accn * dt / 1000.0; accnVector.DirectionRads = powerVector.DirectionRads; Debug.WriteLine("accn = " + accn.ToString()); Vector currentVector = new Vector(); currentVector.Magnitude = base.SpeedMS; currentVector.DirectionRads = base.TravelDirectionRads; Vector newMovementVector = Vector.AddVectors(currentVector, accnVector); base.SpeedMS = newMovementVector.Magnitude; base.TravelDirectionRads = newMovementVector.DirectionRads; return(true); } return(false); }
public override bool Move(double dt) { Debug.WriteLine("dt = " + dt.ToString()); // currently just doing forward motion double forwardPropulsionForce; double rotationalTorque; if (CalculateForceAndTorque(dt, out forwardPropulsionForce, out rotationalTorque) == false) { return(false); } double I; if (PhysicsMaths.CalculateMomentOfInertia(DISK_INERTIA_CONSTANT, ROCKET_MASS_KG, ROCKET_RADIUS, out I) == false) { return(false); } Debug.WriteLine("forwardPropulsionForce = " + forwardPropulsionForce.ToString()); Debug.WriteLine("rotationalTorque = " + rotationalTorque.ToString()); double rotationalFriction; if (PhysicsMaths.CalculateRotationalFrictionTorqueOfDisc(ROCKET_RADIUS, ROCKET_HEIGHT, RateOfRotationRadsSec, AIR_DENSITY, out rotationalFriction) == false) { return(false); } Debug.WriteLine("rotationalFriction = " + rotationalFriction.ToString()); Debug.WriteLine("RateOfRotationRadsSec = " + RateOfRotationRadsSec.ToString()); rotationalTorque = rotationalTorque - rotationalFriction; double rotAccn; if (PhysicsMaths.CalculateRotationalAcceleration(rotationalTorque, I, out rotAccn) == false) { return(false); } // calc rate of rotation RateOfRotationRadsSec += rotAccn; // calc new heading HeadingRads = MovementAssist.RotateHeadingRadians(RateOfRotationRadsSec, HeadingRads, dt); double friction = 0.0; double resultantForce = 0.0; if (PhysicsMaths.CalculateFriction(SpeedMS, CROSS_SECTION, Cd, AIR_DENSITY, out friction)) { Vector powerAndFrictionVector; Debug.WriteLine("HeadingRads = " + HeadingRads.ToString()); Debug.WriteLine(" TravelDirectionRads = " + TravelDirectionRads.ToString()); // calculate the resultant force acting on the if (CalculateResultantForceVector(HeadingRads, forwardPropulsionForce, TravelDirectionRads + Math.PI, friction, out powerAndFrictionVector) == false) { return(false); } Debug.WriteLine("powerAndFrictionVector.Magnitude = " + powerAndFrictionVector.Magnitude.ToString()); if (CalculateNewCourseAndSpeed(powerAndFrictionVector, dt, ROCKET_MASS_KG) == false) { return(false); } } Debug.WriteLine("SpeedMS = " + SpeedMS.ToString()); return(base.Move(dt)); }