diff --git a/GameData/LunarTransferPlanner/Plugins/LunarTransferPlanner.dll b/GameData/LunarTransferPlanner/Plugins/LunarTransferPlanner.dll index 212dd5d..865a377 100644 Binary files a/GameData/LunarTransferPlanner/Plugins/LunarTransferPlanner.dll and b/GameData/LunarTransferPlanner/Plugins/LunarTransferPlanner.dll differ diff --git a/LunarTransferPlanner.cs b/LunarTransferPlanner.cs index bcf3b46..501079a 100644 --- a/LunarTransferPlanner.cs +++ b/LunarTransferPlanner.cs @@ -269,20 +269,23 @@ private OrbitData CalcOrbitForTime(CelestialBody target, Vector3d launchPos, dou double targetTime = Planetarium.GetUniversalTime() + flightTime * 24d * 3600d + delayTime; Vector3d targetPos = target.getPositionAtUT(targetTime); - Vector3d upVector = Quaternion.AngleAxis((float)(delayTime * 360d / mainBody.rotationPeriod), EarthAxis) * (launchPos - EarthPos).normalized; + Vector3d upVector = QuaternionD.AngleAxis(delayTime * 360d / mainBody.rotationPeriod, EarthAxis) * (launchPos - EarthPos).normalized; Vector3d orbitNorm = Vector3d.Cross(targetPos - EarthPos, upVector).normalized; - double inclination = Math.Acos(Vector3d.Dot(orbitNorm, mainBody.angularVelocity.normalized)); + double inclination = Math.Acos(Vector3d.Dot(orbitNorm, EarthAxis)); if (inclination > Math.PI / 2) + { inclination = Math.PI - inclination; + orbitNorm *= -1; // make sure orbitNorm always points roughly northwards + } - Vector3d eastVec = Vector3d.Cross(EarthAxis, upVector).normalized; + // When checking this: remember that Unity (and KSP) use a left-handed coordinate system; therefore, the + // cross product follows the left-hand rule. + Vector3d eastVec = Vector3d.Cross(upVector, EarthAxis).normalized; Vector3d northVec = Vector3d.Cross(eastVec, upVector).normalized; Vector3d launchVec = Vector3d.Cross(upVector, orbitNorm).normalized; double azimuth = Math.Acos(Vector3d.Dot(launchVec, northVec)); - if (Vector3d.Dot(launchVec, eastVec) < 0d) - azimuth = Math.PI - azimuth; return new OrbitData(orbitNorm, inclination * 180d / Math.PI, azimuth * 180d / Math.PI); } @@ -293,7 +296,7 @@ private double EstimateLaunchTime(CelestialBody target, Vector3d launchPos, doub double t = startTime; OrbitData launchOrbit = CalcOrbitForTime(target, launchPos, t); - if (latitude >= target.orbit.inclination) + if (Math.Abs(latitude) >= target.orbit.inclination) { // High latitude path - find the next easterly launch to the target while (Math.Abs(launchOrbit.azimuth - targetAz) > 0.01d) @@ -424,10 +427,10 @@ void MakeMainWindow(int id) GUILayout.Space(4); GUILayout.Label("Launch Now Incl", GUILayout.ExpandWidth(true)); - GUILayout.Box(new GUIContent($"{(launchOrbit.azimuth > 90d ? -launchOrbit.inclination : launchOrbit.inclination):F2}°", + GUILayout.Box(new GUIContent($"{(launchOrbit.azimuth > 90d ? -launchOrbit.inclination : launchOrbit.inclination):F2}°", "Launch to this inclination now to reach a Lunar parking orbit"), GUILayout.MinWidth(100)); - string tooltip = latitude >= target.orbit.inclination ? + string tooltip = Math.Abs(latitude) >= target.orbit.inclination ? "Launch at this time for an Easterly launch to Lunar parking orbit" : "Launch at this time for a low inclination launch to Lunar parking orbit"; diff --git a/LunarTransferPlanner.csproj b/LunarTransferPlanner.csproj index b84d252..89b632f 100644 --- a/LunarTransferPlanner.csproj +++ b/LunarTransferPlanner.csproj @@ -84,14 +84,15 @@ - - xcopy /y "$(TargetPath)" "$(ProjectDir)/GameData/LunarTransferPlanner\Plugins\" - + - --> - \ No newline at end of file +