Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. private Torque GetTorqueVectors()
  2. {
  3. ReferenceFrame frame = Part.Vessel.ReferenceFrame;
  4. double torqueXn = 0;
  5. double torqueX = 0;
  6. double torqueZ = 0;
  7. double torqueZn = 0;
  8. double torqueY = 0;
  9. double torqueYn = 0;
  10. Tuple3 position = Part.Position(frame);
  11. float thrust = MaxThrust;
  12. foreach (var thruster in Thrusters)
  13. {
  14.  
  15. double torque = 0;
  16. double forceX = thruster.ThrustDirection(frame).Item1;
  17. double forceY = thruster.ThrustDirection(frame).Item2;
  18. double forceZ = thruster.ThrustDirection(frame).Item3;
  19. //
  20. double posX = position.Item1;
  21. double posY = position.Item2;
  22. double posZ = position.Item3;
  23. //Pitch torque, around X (position of RCS module projected on Z):
  24. torque = posZ * forceY * thrust;
  25. if (torque > 0) torqueX += torque;
  26. else torqueXn += torque;
  27. //Pitch torque, around X (position projected on Y):
  28. torque = posY * forceZ * thrust;
  29. if (torque < 0) torqueX += torque;
  30. else torqueXn += torque;
  31. //Yaw torque, around Z (position projected on X):
  32. torque = posX * forceY * thrust;
  33. if (torque > 0) torqueZn += torque;
  34. else torqueZ += torque;
  35. //Yaw torque, around Z (position projected on Y):
  36. torque = posY * forceX * thrust;
  37. if (torque < 0) torqueZn += torque;
  38. else torqueZ += torque;
  39. //Roll torque, around Y (position projected on Z):
  40. torque = posZ * forceX * thrust;
  41. if (torque < 0) torqueY += torque;
  42. else torqueYn += torque;
  43. //Roll torque, around Y (position projected on X):
  44. torque = posX * forceZ * thrust;
  45. if (torque < 0) torqueYn += torque;
  46. else torqueY += torque;
  47.  
  48.  
  49. }
  50. Vector3d posd = new Vector3d(torqueX, torqueZ, torqueY);
  51. Vector3d negd = new Vector3d(torqueXn, torqueZn, torqueYn);
  52. return new Torque(posd, negd);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement