Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Phys_Body AppliedForce(double gravity, double mu, double incline, double fMag, double fDir, double time)
- {
- mu *= -1;
- double weight = gravity * Mass;
- if (incline == 0 && fDir == 0)
- {
- double forceNormal = weight * -1;
- double fs = mu * forceNormal;
- double fnet = weight + forceNormal + fs + fMag;
- double acceleration = fnet / Mass;
- double vf = Velocity.X * time + acceleration * time;
- double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
- return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
- }
- else if (incline == 0 && fDir != 0)
- {
- double cos = fMag * Math.Cos(Functions.ToRadians(fDir));
- double sin = fMag * Math.Sin(Functions.ToRadians(fDir));
- double forceNormal = weight * -1;
- forceNormal = forceNormal - sin;
- double fs = mu * forceNormal;
- double fnet = cos + fs;
- double acceleration = fnet / Mass;
- double vf = Velocity.X * time + acceleration * time;
- double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
- return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
- }
- else if (incline != 0 && fDir == 0)
- {
- double fg = weight * Math.Sin(Functions.ToRadians(incline));
- double fn = weight * Math.Cos(Functions.ToRadians(incline)) * -1;
- double fs = mu * fn;
- double fnet = fg + fMag + fs;
- double acceleration = fnet / Mass;
- double vf = Velocity.X * time + acceleration * time;
- double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
- return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
- }
- else
- {
- double sin = fMag * Math.Sin(Functions.ToRadians(fDir));
- double cos = fMag * Math.Cos(Functions.ToRadians(fDir));
- double sin1 = weight * Math.Sin(Functions.ToRadians(incline));
- double cos1 = weight * Math.Cos(Functions.ToRadians(incline)) *-1;
- double fn = cos1 - sin;
- double fa = sin1 + cos;
- double fs = mu * fn;
- double fnet = fa + fs;
- double acceleration = fnet / Mass;
- double vf = Velocity.X * time + acceleration * time;
- double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
- return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
- }
- }
- //Tester
- // Create Objects for the test
- Phys_Body body = new Phys_Body(mass, new Eng_Vector3D(), new Eng_Vector3D(vX, vY, vZ), new Eng_Vector3D(), radius);
- // Perform the test
- body = body.AppliedForce(gravity, mu, incline, fMag, fDir, t);
- // Assert
- Assert.AreEqual(expPx, Math.Round(body.Position.X, 4));
- Assert.AreEqual(expPy, Math.Round(body.Position.Y, 4));
- Assert.AreEqual(expPz, Math.Round(body.Position.Z, 4));
- Assert.AreEqual(expVx, Math.Round(body.Velocity.X, 4));
- Assert.AreEqual(expVy, Math.Round(body.Velocity.Y, 4));
- Assert.AreEqual(expVz, Math.Round(body.Velocity.Z, 4));
- Assert.AreEqual(expAx, Math.Round(body.Acceleration.X, 4));
- Assert.AreEqual(expAy, Math.Round(body.Acceleration.Y, 4));
- Assert.AreEqual(expAz, Math.Round(body.Acceleration.Z, 4));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement