Exemplo n.º 1
0
        public static AgcTuple nodeVector(double inc, string direction)
        {
            var b = Math.Tan(90 - inc) *
                    Math.Tan(Globals.KrpConnection.SpaceCenter().ActiveVessel.Flight().Latitude);

            b = Math.Asin(Math.Min(Math.Max(-1, b), 1));
            var yVec = new AgcTuple(0, 1, 0);

            var longitudeVector = AgcMath.map(
                yVec,
                AgcMath.normalize(Globals.KrpConnection.SpaceCenter().ActiveVessel.Orbit.Body.Position(
                                      Globals.KrpConnection.SpaceCenter().ActiveVessel.ReferenceFrame
                                      ))
                );

            switch (direction)
            {
            case "north":
                return(rodrigues(longitudeVector, yVec, b));

            case "south":
                return(rodrigues(longitudeVector, yVec, 180 - b));

            default:
                return(nodeVector(inc, "north"));
            }
        }
Exemplo n.º 2
0
 public static AgcTuple cross(AgcTuple left, AgcTuple right)
 {
     return(new AgcTuple(
                left.Y * right.Z - left.Z * right.Y,
                left.Z * right.X - left.X * right.Z,
                left.X * right.Y - left.Y * right.X
                ));
 }
Exemplo n.º 3
0
 public static double magnitude(AgcTuple agcTuple)
 {
     return(Math.Sqrt(
                Math.Pow(agcTuple.X, 2) +
                Math.Pow(agcTuple.Y, 2) +
                Math.Pow(agcTuple.Z, 2)
                ));
 }
Exemplo n.º 4
0
        public static double angle(AgcTuple from, AgcTuple to)
        {
            var d   = dot(from, to);
            var mag = magnitude(from) * magnitude(to);
            var b   = Math.Min(Math.Max(d / mag, 1), -1);

            var a = Math.Acos(b);

            return(a);
        }
Exemplo n.º 5
0
        public static AgcTuple rodrigues(AgcTuple inVector, AgcTuple axis, double angle)
        {
            axis = AgcMath.normalize(axis);
            var outVector = inVector * Math.Cos(angle);

            outVector += AgcMath.cross(axis, inVector) * Math.Sin(angle);
            outVector += axis * AgcMath.dot(axis, inVector) * (1 - Math.Cos(angle));

            return(outVector);
        }
Exemplo n.º 6
0
        public static AgcTuple aimAndRoll(AgcTuple aimingVector, double rollAngle)
        {
            AgcTuple up = Globals.KrpConnection.SpaceCenter().TransformDirection(
                new AgcTuple(0, 0, -1),
                Globals.KrpConnection.SpaceCenter().ActiveVessel.ReferenceFrame,
                Globals.KrpConnection.SpaceCenter().ActiveVessel.SurfaceReferenceFrame
                );

            AgcTuple rollVector = rodrigues(up, aimingVector, -rollAngle);

            return(aimingVector * rollVector);
        }
Exemplo n.º 7
0
        public static AgcTuple solarPrimeVector(ReferenceFrame referenceFrame)
        {
            var      sun = Globals.KrpConnection.SpaceCenter().Bodies["Sun"];
            var      secondsPerDegree = sun.RotationalPeriod / 360;
            var      rotationOffset   = (Globals.KrpConnection.SpaceCenter().UT / secondsPerDegree) % 360;
            AgcTuple sunPosition      = sun.Position(referenceFrame);
            AgcTuple sunPosition2     = sun.SurfacePosition(0, 0 - rotationOffset, referenceFrame);


            var primeVector = sunPosition2 - sunPosition;

            return(AgcMath.normalize(primeVector));
        }
Exemplo n.º 8
0
        public static double orbitInterceptTime(string direction)
        {
            var targetInc = Globals.MissionData.Inclination;
            var targetLan = Globals.MissionData.Lan;

            if (direction == "nearest")
            {
                var    timeToNortherly = orbitInterceptTime("north");
                var    timeToSoutherly = orbitInterceptTime("south");
                double time;

                if (timeToSoutherly < timeToNortherly)
                {
                    Globals.MissionData.Direction = "south";
                    time = timeToSoutherly;
                }
                else
                {
                    Globals.MissionData.Direction = "north";
                    time = timeToNortherly;
                }
                return(time);
            }

            Globals.CurrentNode = nodeVector(targetInc, direction);
            AgcTuple targetNode = rodrigues(Globals.VehicleData.getSolarPrimeVector(), new AgcTuple(0, 1, 0), -targetLan);
            var      nodeDelta  = AgcMath.angle(Globals.CurrentNode, targetNode);
            var      deltaDir   = AgcMath.dot(new AgcTuple(0, 1, 0), AgcMath.cross(targetNode, Globals.CurrentNode));

            if (deltaDir < 0)
            {
                nodeDelta = 360 - nodeDelta;
            }

            var deltatime = Globals.KrpConnection.SpaceCenter().ActiveVessel.Orbit.Body.RotationalPeriod *
                            nodeDelta / 360;

            return(deltatime);
        }
Exemplo n.º 9
0
 public static AgcTuple normalize(AgcTuple tuple)
 {
     return(tuple / magnitude(tuple));
 }
Exemplo n.º 10
0
 public static AgcTuple map(AgcTuple from, AgcTuple to)
 {
     return(dot(from, to) / Math.Pow(magnitude(to), 2) * to);
 }
Exemplo n.º 11
0
 public static double dot(AgcTuple left, AgcTuple right)
 {
     return(left.X * right.X + left.Y * right.Y + left.Z + right.Z);
 }
Exemplo n.º 12
0
 public static AgcTuple vecYZ(AgcTuple input)
 {
     return(new AgcTuple(input.X, input.Z, input.Y));
 }