public AoAPoint(AeroPredictor vessel, CelestialBody body, float altitude, float speed, float AoA) { this.altitude = altitude; this.speed = speed; AeroPredictor.Conditions conditions = new AeroPredictor.Conditions(body, speed, altitude); this.AoA = AoA; this.mach = conditions.mach; this.dynamicPressure = 0.0005f * conditions.atmDensity * speed * speed; this.pitchInput = vessel.GetPitchInput(conditions, AoA); this.pitchInput_dry = vessel.GetPitchInput(conditions, AoA, true); Vector3 force = AeroPredictor.ToFlightFrame(vessel.GetAeroForce(conditions, AoA, pitchInput), AoA); torque = vessel.GetAeroTorque(conditions, AoA).x; torque_dry = vessel.GetAeroTorque(conditions, AoA, 0, true).x; Lift = force.y; Drag = -force.z; LDRatio = Mathf.Abs(Lift / Drag); dLift = (vessel.GetLiftForceMagnitude(conditions, AoA + WindTunnelWindow.AoAdelta, pitchInput) - Lift) / (WindTunnelWindow.AoAdelta * Mathf.Rad2Deg); }
private static void GetStabilityValues(AeroPredictor vessel, AeroPredictor.Conditions conditions, float AoA_centre, out float stabilityRange, out float stabilityScore) { const int step = 5; const int range = 90; const int alphaSteps = range / step; float[] torques = new float[2 * alphaSteps + 1]; float[] aoas = new float[2 * alphaSteps + 1]; int start, end; for (int i = 0; i <= 2 * alphaSteps; i++) { aoas[i] = (i - alphaSteps) * step * Mathf.Deg2Rad; torques[i] = vessel.GetAeroTorque(conditions, aoas[i], 0).x; } int eq = 0 + alphaSteps; int dir = (int)Math.Sign(torques[eq]); if (dir == 0) { start = eq - 1; end = eq + 1; } else { while (eq > 0 && eq < 2 * alphaSteps) { eq += dir; if (Math.Sign(torques[eq]) != dir) { break; } } if (eq == 0 || eq == 2 * alphaSteps) { stabilityRange = 0; stabilityScore = 0; return; } if (dir < 0) { start = eq; end = eq + 1; } else { start = eq - 1; end = eq; } } while (torques[start] > 0 && start > 0) { start -= 1; } while (torques[end] < 0 && end < 2 * alphaSteps - 1) { end += 1; } float min = (Mathf.InverseLerp(torques[start], torques[start + 1], 0) + start) * step; float max = (-Mathf.InverseLerp(torques[end], torques[end - 1], 0) + end) * step; stabilityRange = max - min; stabilityScore = 0; for (int i = start; i < end; i++) { stabilityScore += (torques[i] + torques[i + 1]) / 2 * step; } }