Ejemplo n.º 1
0
        /// <summary>
        /// Recalculate CurrentTransition value.
        /// </summary>
        public void CalculateTransitionState()
        {
            var refs = GetBodiesReferences();

            if (refs.Attractor != null)
            {
                Vector3d startPoint       = GetPositionAtGivenTime(refs.Origin, (StartTimeOffset), refs.OriginAttractorsChain);
                Vector3d endPoint         = GetPositionAtGivenTime(refs.Target, (StartTimeOffset + TargetDuration), refs.TargetAttractorsChain);
                var      attractorPosHalf = refs.Attractor.position;
                var      attractorPos     = new Vector3d(attractorPosHalf.x, attractorPosHalf.y, attractorPosHalf.z);
                var      hyperbola        = new HyperbolaData(new Vector3d(startPoint.x, startPoint.y, startPoint.z), endPoint, attractorPos);
                var      trajectory       = CalcTransitionTrajectory(
                    startPoint,
                    endPoint,
                    attractorPos,
                    hyperbola,
                    this.TargetDuration,
                    isReverseOrbit: this.IsTransitionPassBehindAttractor,
                    attrMass: refs.AttractorMass,
                    g: refs.GConst,
                    precision: this.TargetDurationPrecision,
                    semiMajorAxisUpperLimit: this.MaxTransitionSemiMajorAxis);

                if (trajectory.orbit != null && trajectory.orbit.IsValidOrbit && trajectory.Duration > 0 && !double.IsInfinity(trajectory.Duration))
                {
                    var velocityDiff = CalculateVelocityDifference(refs.Origin, refs.Target, trajectory.orbit, StartTimeOffset, trajectory.Duration, trajectory.EccAnomStart, trajectory.EccAnomEnd);
                    var totalDeltaV  = 0.0;
                    for (int i = 0; i < velocityDiff.Count; i++)
                    {
                        totalDeltaV += velocityDiff[i].magnitude;
                    }

                    _currentTransition = new TransitionOrbitData()
                    {
                        Attractor          = refs.Attractor,
                        Duration           = (float)trajectory.Duration,
                        EccAnomalyStart    = (float)trajectory.EccAnomStart,
                        EccAnomalyEnd      = (float)trajectory.EccAnomEnd,
                        ImpulseDifferences = velocityDiff,
                        Orbit       = trajectory.orbit,
                        TotalDeltaV = (float)totalDeltaV,
                    };
                }
                else
                {
                    _currentTransition = null;
                }
            }
            else
            {
                _currentTransition = null;
            }
        }
        private void GizmosDrawSingleTransition(TransitionOrbitData transition)
        {
            Gizmos.color = Color.green;
            int     steps     = 50;
            float   delta     = transition.EccAnomalyEnd - transition.EccAnomalyStart;
            Vector3 lastPoint = (Vector3)transition.Orbit.GetFocalPositionAtEccentricAnomaly(transition.EccAnomalyStart);
            Vector3 point     = lastPoint;

            for (int i = 1; i <= steps; i++)
            {
                var ratio = i / (float)steps;
                point = (Vector3)transition.Orbit.GetFocalPositionAtEccentricAnomaly(transition.EccAnomalyStart + delta * ratio);
                Gizmos.DrawLine(transition.Attractor.position + lastPoint, transition.Attractor.position + point);
                lastPoint = point;
            }
        }
Ejemplo n.º 3
0
        private void GizmosDrawSingleTransition(TransitionOrbitData transition)
        {
            Gizmos.color = Color.green;
            int   steps     = 50;
            float delta     = transition.EccAnomalyEnd - transition.EccAnomalyStart;
            var   lastPoint = transition.Orbit.GetFocalPositionAtEccentricAnomaly(transition.EccAnomalyStart);
            var   point     = lastPoint;

            for (int i = 1; i <= steps; i++)
            {
                var ratio = i / (float)steps;
                point = transition.Orbit.GetFocalPositionAtEccentricAnomaly(transition.EccAnomalyStart + delta * ratio);
                var attractorPos = transition.Attractor.position;
                Gizmos.DrawLine(
                    attractorPos + new Vector3((float)lastPoint.x, (float)lastPoint.y, (float)lastPoint.z),
                    attractorPos + new Vector3((float)point.x, (float)point.y, (float)point.z));
                lastPoint = point;
            }
        }