Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. public Phys_Body AppliedForce(double gravity, double mu, double incline, double fMag, double fDir, double time)
  2. {
  3. mu *= -1;
  4.  
  5. double weight = gravity * Mass;
  6.  
  7. if (incline == 0 && fDir == 0)
  8. {
  9. double forceNormal = weight * -1;
  10. double fs = mu * forceNormal;
  11.  
  12. double fnet = weight + forceNormal + fs + fMag;
  13.  
  14. double acceleration = fnet / Mass;
  15. double vf = Velocity.X * time + acceleration * time;
  16. double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
  17.  
  18. return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
  19. }
  20. else if (incline == 0 && fDir != 0)
  21. {
  22. double cos = fMag * Math.Cos(Functions.ToRadians(fDir));
  23. double sin = fMag * Math.Sin(Functions.ToRadians(fDir));
  24.  
  25. double forceNormal = weight * -1;
  26. forceNormal = forceNormal - sin;
  27. double fs = mu * forceNormal;
  28.  
  29. double fnet = cos + fs;
  30.  
  31. double acceleration = fnet / Mass;
  32. double vf = Velocity.X * time + acceleration * time;
  33. double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
  34.  
  35. return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
  36. }
  37. else if (incline != 0 && fDir == 0)
  38. {
  39.  
  40. double fg = weight * Math.Sin(Functions.ToRadians(incline));
  41. double fn = weight * Math.Cos(Functions.ToRadians(incline)) * -1;
  42.  
  43. double fs = mu * fn;
  44. double fnet = fg + fMag + fs;
  45.  
  46. double acceleration = fnet / Mass;
  47. double vf = Velocity.X * time + acceleration * time;
  48. double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
  49.  
  50. return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
  51. }
  52. else
  53. {
  54. double sin = fMag * Math.Sin(Functions.ToRadians(fDir));
  55. double cos = fMag * Math.Cos(Functions.ToRadians(fDir));
  56.  
  57. double sin1 = weight * Math.Sin(Functions.ToRadians(incline));
  58. double cos1 = weight * Math.Cos(Functions.ToRadians(incline)) *-1;
  59.  
  60. double fn = cos1 - sin;
  61. double fa = sin1 + cos;
  62. double fs = mu * fn;
  63. double fnet = fa + fs;
  64.  
  65. double acceleration = fnet / Mass;
  66. double vf = Velocity.X * time + acceleration * time;
  67. double d = Velocity.X * time + 0.5 * acceleration * Math.Pow(time, 2);
  68.  
  69. return new Phys_Body(Mass, new Eng_Vector3D(d, 0, 0), new Eng_Vector3D(vf, 0, 0), new Eng_Vector3D(acceleration, 0, 0), Radius);
  70. }
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. //Tester
  80.  
  81. // Create Objects for the test
  82. Phys_Body body = new Phys_Body(mass, new Eng_Vector3D(), new Eng_Vector3D(vX, vY, vZ), new Eng_Vector3D(), radius);
  83.  
  84. // Perform the test
  85. body = body.AppliedForce(gravity, mu, incline, fMag, fDir, t);
  86.  
  87. // Assert
  88. Assert.AreEqual(expPx, Math.Round(body.Position.X, 4));
  89. Assert.AreEqual(expPy, Math.Round(body.Position.Y, 4));
  90. Assert.AreEqual(expPz, Math.Round(body.Position.Z, 4));
  91.  
  92. Assert.AreEqual(expVx, Math.Round(body.Velocity.X, 4));
  93. Assert.AreEqual(expVy, Math.Round(body.Velocity.Y, 4));
  94. Assert.AreEqual(expVz, Math.Round(body.Velocity.Z, 4));
  95.  
  96. Assert.AreEqual(expAx, Math.Round(body.Acceleration.X, 4));
  97. Assert.AreEqual(expAy, Math.Round(body.Acceleration.Y, 4));
  98. Assert.AreEqual(expAz, Math.Round(body.Acceleration.Z, 4));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement