internal OrbitOrderWiget(Entity targetEntity) : base(targetEntity.GetDataBlob <PositionDB>()) { _bodyPositionDB = targetEntity.GetDataBlob <PositionDB>(); OrbitEllipseSemiMaj_m = 20000; OrbitEllipseSemiMinor_m = 20000; _linearEccentricity_m = 0; _soiWorldRadius_AU = OrbitProcessor.GetSOI_AU(targetEntity); _targetWorldRadius_AU = targetEntity.GetDataBlob <MassVolumeDB>().RadiusInAU; Setup(); }
void TargetSelected() { TargetEntity = _uiState.LastClickedEntity; _uiState.Camera.PinToEntity(TargetEntity.Entity); _targetRadiusAU = TargetEntity.Entity.GetDataBlob <MassVolumeDB>().RadiusInAU; _targetRadius_m = TargetEntity.Entity.GetDataBlob <MassVolumeDB>().RadiusInM; var soiWorldRad_AU = OrbitProcessor.GetSOI_AU(TargetEntity.Entity); _apMax = soiWorldRad_AU; float soiViewUnits = _uiState.Camera.ViewDistance(soiWorldRad_AU); _massTargetBody = TargetEntity.Entity.GetDataBlob <MassVolumeDB>().MassDry; _stdGravParamTargetBody_m = OrbitMath.CalculateStandardGravityParameterInM3S2(_massOrderingEntity, _massTargetBody); InsertionCalcs(); System.Numerics.Vector2 viewPortSize = _uiState.Camera.ViewPortSize; float windowLen = Math.Min(viewPortSize.X, viewPortSize.Y); if (soiViewUnits < windowLen * 0.5) { //zoom so soi fills ~3/4 screen. var soilenwanted = windowLen * 0.375; _uiState.Camera.ZoomLevel = (float)(soilenwanted / _apMax); } if (_orbitWidget != null) { _orbitWidget = new OrbitOrderWiget(TargetEntity.Entity); _uiState.SelectedSysMapRender.UIWidgets[nameof(_orbitWidget)] = _orbitWidget; } else { _orbitWidget = new OrbitOrderWiget(TargetEntity.Entity); _uiState.SelectedSysMapRender.UIWidgets.Add(nameof(_orbitWidget), _orbitWidget); } OrderingEntityState.DebugOrbitOrder = _orbitWidget; _moveWidget.SetArrivalTarget(TargetEntity.Entity); _tooltipText = "Select Insertion Point"; CurrentState = States.NeedsInsertionPoint; }
public OrbitOrderWiget(OrbitDB orbitDB) : base(orbitDB.Parent.GetDataBlob <PositionDB>()) { var targetEntity = orbitDB.Parent; _bodyPositionDB = targetEntity.GetDataBlob <PositionDB>(); OrbitEllipseSemiMaj_m = (float)orbitDB.SemiMajorAxis; _eccentricity = orbitDB.Eccentricity; EllipseMath.SemiMinorAxis(OrbitEllipseSemiMaj_m, _eccentricity); _linearEccentricity_m = (float)(orbitDB.Eccentricity * OrbitEllipseSemiMaj_m); _soiWorldRadius_AU = OrbitProcessor.GetSOI_AU(targetEntity); _targetWorldRadius_AU = targetEntity.GetDataBlob <MassVolumeDB>().RadiusInAU; Setup(); }
internal void CreatePointArray() { _dv = _newtonMoveDB.DeltaVForManuver_m.Length(); Vector3 vel = Distance.MToAU(_newtonMoveDB.CurrentVector_ms); Vector3 pos = myPosDB.RelativePosition_AU; Vector3 eccentVector = OrbitMath.EccentricityVector(_sgp, pos, vel); double e = eccentVector.Length(); double r = pos.Length(); double v = vel.Length(); double a = 1 / (2 / r - Math.Pow(v, 2) / _sgp); //semiMajor Axis double b = -a *Math.Sqrt(Math.Pow(e, 2) - 1); //semiMinor Axis double linierEccentricity = e * a; double soi = OrbitProcessor.GetSOI_AU(_newtonMoveDB.SOIParent); //longditudeOfPeriapsis; double _lop = Math.Atan2(eccentVector.Y, eccentVector.X); if (Vector3.Cross(pos, vel).Z < 0) //anti clockwise orbit { _lop = Math.PI * 2 - _lop; } double p = EllipseMath.SemiLatusRectum(a, e); double angleToSOIPoint = Math.Abs(OrbitMath.AngleAtRadus(soi, p, e)); //double thetaMax = angleToSOIPoint; double maxX = soi * Math.Cos(angleToSOIPoint); //maxX = maxX - a + linierEccentricity; double foo = maxX / a; double thetaMax = Math.Log(foo + Math.Sqrt(foo * foo - 1)); if (_numberOfPoints % 2 == 0) { _numberOfPoints += 1; } int ctrIndex = _numberOfPoints / 2; double dtheta = thetaMax / (ctrIndex - 1); double fooA = Math.Cosh(dtheta); double fooB = (a / b) * Math.Sinh(dtheta); double fooC = (b / a) * Math.Sinh(dtheta); double xn = a; double yn = 0; var points = new PointD[ctrIndex + 1]; points[0] = new PointD() { X = xn, Y = yn }; for (int i = 1; i < ctrIndex + 1; i++) { var lastx = xn; var lasty = yn; xn = fooA * lastx + fooB * lasty; yn = fooC * lastx + fooA * lasty; points[i] = new PointD() { X = xn, Y = yn }; } _points = new PointD[_numberOfPoints]; _points[ctrIndex] = new PointD() { X = ((points[0].X - linierEccentricity) * Math.Cos(_lop)) - (points[0].Y * Math.Sin(_lop)), Y = ((points[0].X - linierEccentricity) * Math.Sin(_lop)) + (points[0].Y * Math.Cos(_lop)) }; for (int i = 1; i < ctrIndex + 1; i++) { double x = points[i].X - linierEccentricity; //adjust for the focal point double ya = points[i].Y; double yb = -points[i].Y; double x2a = (x * Math.Cos(_lop)) - (ya * Math.Sin(_lop)); //rotate to loan double y2a = (x * Math.Sin(_lop)) + (ya * Math.Cos(_lop)); double x2b = (x * Math.Cos(_lop)) - (yb * Math.Sin(_lop)); double y2b = (x * Math.Sin(_lop)) + (yb * Math.Cos(_lop)); _points[ctrIndex + i] = new PointD() { X = x2a, Y = y2a }; _points[ctrIndex - i] = new PointD() { X = x2b, Y = y2b }; } }