Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. public void CartToKep(Vector3D pos, Vector3D vel)//This doesn't work, feel free to try and fix it.
  2. {
  3. this.pos = pos;
  4. this.vel = vel;
  5. en = vel.LengthSquared() / 2 - planet.u / pos.Length();
  6. a = Math.Abs(planet.u / (2 * en));
  7. h = Vector3D.Cross(pos, vel);
  8. E = Vector3D.Cross(vel, h) / planet.u - (pos / pos.Length());
  9. Console.WriteLine(E);
  10. e = E.Length();
  11. I = Math.Acos(h.GetDim(2) / h.Length());
  12. N = new Vector3D(-h.GetDim(1), h.GetDim(0), 0);
  13. if (N.GetDim(1) >= 0)
  14. {
  15. q = Math.Acos(N.GetDim(0) / N.Length());
  16. q = double.IsNaN(q) ? 0 : q;
  17. }
  18. else
  19. {
  20. q = 2 * Math.PI - Math.Acos(N.GetDim(0) / N.Length());
  21. q = double.IsNaN(q) ? 2*Math.PI : q;
  22. }
  23.  
  24. n = Math.Sqrt(planet.u / Math.Pow(a, 3));
  25. if (q != 0)
  26. {
  27. w = E.GetDim(2) >= 0 ? Math.Acos(Vector3D.Dot(N, E) / (N.Length() * E.Length())) : Math.PI * 2 - Math.Acos(Vector3D.Dot(N, E) / (N.Length() * E.Length()));
  28.  
  29. }
  30. else
  31. {
  32. double W=Math.Atan2(E.GetDim(1),E.GetDim(0));
  33. w = h.GetDim(2) < 0 ? 2*Math.PI-W:W;
  34.  
  35.  
  36. }
  37.  
  38. if (double.IsNaN(w)) w = 0;
  39. if (w < 0) w += Math.PI * 2;
  40. epoch = DateTime.Now;
  41. if (E.Length() != 0)
  42. {
  43. v = Vector3D.Dot(pos, vel) >= 0 ? Math.Acos(Vector3D.Dot(E, pos) / (E.Length() * pos.Length())) : Math.PI * 2 - Math.Acos(Vector3D.Dot(E, pos) / (E.Length() * pos.Length()));
  44. }
  45. else
  46. {
  47. if (I != 0)
  48. {
  49. v = Vector3D.Dot(N, vel) <= 0 ? Math.Acos(Vector3D.Dot(N, pos) / (N.Length() * pos.Length())) : Math.PI * 2 - Math.Acos(Vector3D.Dot(N, pos) / (N.Length() * pos.Length()));
  50. Console.WriteLine(N);
  51. }
  52. else
  53. {
  54. v = vel.GetDim(0) <= 0 ? Math.Acos(pos.GetDim(0) / (pos.Length())) : Math.PI * 2 - Math.Acos(pos.GetDim(0) / (pos.Length()));
  55. }
  56. }
  57. if (double.IsNaN(v)) v = 0;
  58. lastTa = v;
  59. double sinE = sin(a) * Math.Sqrt(1 - Math.Pow(e, 2)) / (1 + e * cos(a));
  60. double cosE = (e + cos(a)) / (1 + e * cos(a));
  61. double Ec = Math.Atan2(sinE, cosE);
  62. EC = 2 * Math.Atan(Math.Tan(v / 2) / Math.Sqrt(1 + e / 1 - e));
  63. EC = EC < 0 ? EC + Math.PI * 2 : EC;
  64. if (double.IsNaN(EC)) EC = 0;
  65. M = EC - e * Math.Sin(EC);
  66. lastM = M;
  67. Period = Math.PI * 2 * Math.Sqrt(Math.Pow(a,3)/planet.u);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement