untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 14 forks source link

Semi-major axis in Orbit structure is wrong #88

Closed plonk-75 closed 1 year ago

plonk-75 commented 1 year ago

KS2 0.4.1 / KSP 0.1.2.0.22258

The value of vessel.orbit.semi_major_axis is wrong. This is easily shown by comparing this value to an in-script calculated SMA, see code below.

code to reproduce:

use { CONSOLE } from ksp::console
// ensure an elliptical orbit, having an eccentricity clearly > 0
pub fn main_flight(vessel: ksp::vessel::Vessel) -> Result<Unit, string> = {
    CONSOLE.clear()

    let sma_calc = vessel.main_body.radius + (vessel.orbit.apoapsis.value + vessel.orbit.periapsis)/2
    let sma_field = vessel.orbit.semi_major_axis
    CONSOLE.print_line("calculated sma :" + sma_calc.to_fixed(4))
    CONSOLE.print_line("vessel.orbit.semi_major_axis :" + sma_field.to_fixed(4))
}

Possible cause: Wrong assignment in KSP2Runtime/KSPOrbit/OrbitWrapper.cs at line 32:

public double SemiMajorAxis => orbit.SemiMinorAxis;

This would explain why it went undetected, as semi-minor axis and semi-major axis converge for eccentricity -> 0. I am neither an expert in C# nor modding, so this is just an educated guess. :)

plonk-75 commented 1 year ago

The above code's output compared to Micro Engineer: KS_ME_crosscheck

untoldwind commented 1 year ago

Should be fixed 0.4.1.2

plonk-75 commented 1 year ago

Fix confirmed from my side.