Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. internal void CreatePointArray()
  2. {
  3.  
  4. Vector4 vel = Distance.KmToAU(_newtonMoveDB.CurrentVector_kms);
  5. Vector4 pos = myPosDB.RelativePosition_AU;
  6. Vector4 eccentVector = OrbitMath.EccentricityVector(_sgp, pos, vel);
  7. double e = eccentVector.Length();
  8. double r = pos.Length();
  9. double v = vel.Length();
  10. double a = 1 / (2 / r - Math.Pow(v, 2) / _sgp); //semiMajor Axis
  11. double b = -a * Math.Sqrt(Math.Pow(e, 2) - 1); //semiMinor Axis
  12. double linierEccentricity = e * a;
  13. double soi = OrbitProcessor.GetSOI(_newtonMoveDB.SOIParent);
  14.  
  15. //longditudeOfPeriapsis;
  16. double _lop = Math.Atan2(eccentVector.Y, eccentVector.X);
  17. if (Vector4.Cross(pos, vel).Z < 0) //anti clockwise orbit
  18. _lop = Math.PI * 2 - _lop;
  19.  
  20. double p = EllipseMath.SemiLatusRectum(a, e);
  21. double angleToSOIPoint = Math.Abs(OrbitMath.AngleAtRadus(soi, p, e));
  22. double thetaMax = angleToSOIPoint;
  23.  
  24. if (_numberOfPoints % 2 == 0)
  25. _numberOfPoints += 1;
  26. int ctrIndex = _numberOfPoints / 2;
  27. double dtheta = thetaMax / (ctrIndex -1);
  28. double fooA = Math.Cosh(dtheta);
  29. double fooB = (a / b) * Math.Sinh(dtheta);
  30. double fooC = (b / a) * Math.Sinh(dtheta);
  31. double xn = a;
  32. double yn = 0;
  33.  
  34. var points = new PointD[ctrIndex + 1];
  35. points[0] = new PointD() { X = xn, Y = yn };
  36. for (int i = 1; i < ctrIndex + 1; i++)
  37. {
  38. var lastx = xn;
  39. var lasty = yn;
  40. xn = fooA * lastx + fooB * lasty;
  41. yn = fooC * lastx + fooA * lasty;
  42. points[i] = new PointD() { X = xn, Y = yn };
  43. }
  44.  
  45.  
  46. _points = new PointD[_numberOfPoints];
  47. _points[ctrIndex] = new PointD()
  48. {
  49. X = ((points[0].X - linierEccentricity )* Math.Cos(_lop)) - (points[0].Y * Math.Sin(_lop)),
  50. Y = ((points[0].X - linierEccentricity) * Math.Sin(_lop)) + (points[0].Y * Math.Cos(_lop))
  51. };
  52. for (int i = 1; i < ctrIndex + 1; i++)
  53. {
  54. double x = points[i].X - linierEccentricity; //adjust for the focal point
  55. double ya = points[i].Y;
  56. double yb = -points[i].Y;
  57. double x2a = (x * Math.Cos(_lop)) - (ya * Math.Sin(_lop)); //rotate to loan
  58. double y2a = (x * Math.Sin(_lop)) + (ya * Math.Cos(_lop));
  59. double x2b = (x * Math.Cos(_lop)) - (yb * Math.Sin(_lop));
  60. double y2b = (x * Math.Sin(_lop)) + (yb * Math.Cos(_lop));
  61. _points[ctrIndex + i] = new PointD()
  62. {
  63. X = x2a,
  64. Y = y2a
  65. };
  66.  
  67. _points[ctrIndex - i] = new PointD()
  68. {
  69. X = x2b,
  70. Y = y2b
  71. };
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement