Advertisement
Guest User

Untitled

a guest
May 10th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. ```cs
  2.  
  3. void DrawPatchedConic() { Vector2[] points = new Vector2[conicSize];
  4. var min = (gObject.elements.eccentricity < 1) ? 0 : - OrbitalCalculator.AdvancedOrbital.turnAngle(gObject.elements.eccentricity); var max = (gObject.elements.eccentricity < 1) ? 2 * Mathf.PI : OrbitalCalculator.AdvancedOrbital.turnAngle(gObject.elements.eccentricity);
  5. for (int i = 1; i <= conicSize; i++) { var trueAnomaly = Mathf.Lerp(min, max, (float)i/(float)(conicSize)); var radius = OrbitalCalculator.OrbitalPoints.radiusFromTrueAnomaly(trueAnomaly, gObject.elements.eccentricity, gObject.elements.semiMajorAxis); points[i-1] = OrbitalCalculator.OrbitalPoints.PositionVectorFromTrueAnomaly(trueAnomaly, radius, gObject.elements.periapsisPosition) + gObject.telemetry.tryGetOrbitCenter.telemetry.currentPosition; }
  6. conicLine.ClearAllPoints(); conicLine.AddPoints(points);
  7. Draw.Polyline(conicLine, gObject.elements.eccentricity < 1, lineThickness, PolylineJoins.Simple, Color.grey); }
  8.  
  9. ```
  10.  
  11. ```cs
  12.  
  13. public static float radiusFromTrueAnomaly(float trueAnomaly, float eccentricity, float semiMajorAxis) => (semiMajorAxis * (1 - Mathf.Pow(eccentricity, 2))) / (1 + eccentricity * Mathf.Cos(trueAnomaly));
  14.  
  15. public static Vector2 PositionVectorFromTrueAnomaly(float trueAnomaly, float radius, Vector2 periapsisPosition) => Tools.RotateVector(periapsisPosition, trueAnomaly).normalized * radius;
  16.  
  17. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement