kOS.Suffixed.VesselTarget.GetPositionAtUT C# (CSharp) Method

GetPositionAtUT() public method

Calculates the position of this vessel at some future universal timestamp, taking into account all currently predicted SOI transition patches, and also assuming that all the planned maneuver nodes will actually be executed precisely as planned. Note that this cannot "see" into the future any farther than the KSP orbit patches setting allows for.
public GetPositionAtUT ( TimeSpan timeStamp ) : Vector
timeStamp TimeSpan The time to predict for. Although the intention is to /// predict for a future time, it could be used to predict for a past time.
return Vector
        public override Vector GetPositionAtUT(TimeSpan timeStamp)
        {
            string blockingTech;
            if (!Career.CanMakeNodes(out blockingTech))
                throw new KOSLowTechException("use POSITIONAT on a vessel", blockingTech);

            double desiredUT = timeStamp.ToUnixStyleTime();

            Orbit patch = GetOrbitAtUT(desiredUT);
            Vector3d pos = patch.getPositionAtUT(desiredUT);

            // This is an ugly workaround to fix what is probably a bug in KSP's API:
            // If looking at a future orbit patch around a child body of the current body, then
            // the various get{Thingy}AtUT() methods return numbers calculated incorrectly as
            // if the child body was going to remain stationary where it is now, rather than
            // taking into account where it will be later when the intercept happens.
            // This corrects for that case:
            if (Utils.BodyOrbitsBody(patch.referenceBody, Vessel.orbit.referenceBody))
            {
                Vector3d futureSOIPosNow = patch.referenceBody.position;
                Vector3d futureSOIPosLater = patch.referenceBody.getPositionAtUT(desiredUT);
                Vector3d offset = futureSOIPosLater - futureSOIPosNow;
                pos = pos + offset;
            }

            return new Vector(pos - Shared.Vessel.CoMD); // Convert to ship-centered frame.
        }