private static void TestCurve(Vector2 start, Vector2 end) { const float amplitude = 1; const float waveLength = 1; // Linear and non-linear curves should start at same position float progress = 0; Vector2 lerpValue = Vector2.Lerp(start, end, progress); Vector2 sCurveValue = NonLinearity.SinusOffset(lerpValue, start, end, amplitude, waveLength); Assert.AreEqual(sCurveValue.Y, lerpValue.Y); // S-Curve should start out below the linear ascent progress = 0.25f; lerpValue = Vector2.Lerp(start, end, progress); sCurveValue = NonLinearity.SinusOffset(lerpValue, start, end, amplitude, waveLength); Assert.Less(sCurveValue.Y, lerpValue.Y); // After catching up the S-Curve should now be above the linear interpolation progress = 0.75f; lerpValue = Vector2.Lerp(start, end, progress); sCurveValue = NonLinearity.SinusOffset(lerpValue, start, end, amplitude, waveLength); Assert.Greater(sCurveValue.Y, lerpValue.Y); // Linear and non-linear curves should end at same position progress = 1.0f; lerpValue = Vector2.Lerp(start, end, progress); sCurveValue = NonLinearity.SinusOffset(lerpValue, start, end, amplitude, waveLength); Assert.AreEqual(sCurveValue.Y, lerpValue.Y); }
public float GetSimulatedStaticPressure(float trueAltitude) { float truePressure = StaticPressureHelper.GetPressure(trueAltitude, SeaLevelStaticPresure); // If we assume the pressure is rising linearly (although it is not) we would want to further distort the // measured pressure by applying non-linearity to the readings. Vector2 lowestPressurePlot = GetPressurePlot(StaticPressureHelper.MinAltitude); Vector2 highestPressurePlot = GetPressurePlot(StaticPressureHelper.MaxAltitude); var pressurePlot = new Vector2(trueAltitude, truePressure); // float nonLinearPressure = NonLinearity.SinusOffset(pressurePlot, lowestPressurePlot, highestPressurePlot).Y; float nonLinearPressure = NonLinearity.SinusOffset(pressurePlot, lowestPressurePlot, highestPressurePlot, 5f, 100).Y; // Noise amplitude is selected to give a few meters of variation, both positive and negative const float pressurePerMeter = 11.989f; const float noiseAmplitudeMeters = 0.5f; const float noiseAmplitudePressure = noiseAmplitudeMeters * pressurePerMeter; return(Noise.WhiteNoise(nonLinearPressure, noiseAmplitudePressure)); }