public static double GetVerticalSpeedFraction( double angle, ZeroDegreesDirection zeroDegreesDirection = ZeroDegreesDirection.Right, int decimals = 3) { return(Math.Round(Math.Sin(ToRadians(angle + GetAdjustedAngle(zeroDegreesDirection))), decimals)); }
private static int GetAdjustedAngle(ZeroDegreesDirection zeroDegreesDirection) { return(zeroDegreesDirection switch { ZeroDegreesDirection.Top => 90, ZeroDegreesDirection.Left => 180, ZeroDegreesDirection.Bottom => 270, ZeroDegreesDirection.Right => 0, _ => throw new ArgumentOutOfRangeException(nameof(zeroDegreesDirection), zeroDegreesDirection, null) });
/// <summary>Moves the object. Gravity needs to be positive (gets reverted within the method).</summary> public void ApplyThrust( Thrust thrust, double gravity, ZeroDegreesDirection zeroDegreesDirection = ZeroDegreesDirection.Top) { StateHistory.Add(State.Clone()); State.XSpeed += Trigonometry.GetHorizontalSpeedFraction(thrust.Rotation, zeroDegreesDirection) * thrust.Power; State.YSpeed += Trigonometry.GetVerticalSpeedFraction(thrust.Rotation, zeroDegreesDirection) * thrust.Power - gravity; State.Power = thrust.Power; State.X += State.XSpeed; State.Y += State.YSpeed; State.Rotation = thrust.Rotation; }