46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Car_simulation
|
|
{
|
|
public class Util
|
|
{
|
|
public static float Lerp(float a, float b, float t)
|
|
{
|
|
return a + (b - a) * t;
|
|
}
|
|
}
|
|
|
|
public static class PhysicsUtil
|
|
{
|
|
public const float G = 9.81f;
|
|
public const float AirDensity = 1.225f;
|
|
|
|
public static float Lerp(float a, float b, float t)
|
|
{
|
|
t = Math.Clamp(t, 0f, 1f);
|
|
return a + (b - a) * t;
|
|
}
|
|
|
|
public static float RPMToOmega(float rpm) => rpm * MathF.PI * 2f / 60f;
|
|
public static float OmegaToRPM(float omega) => omega * 60f / (2f * MathF.PI);
|
|
|
|
// Calculate kinetic energy: 0.5 * I * ω²
|
|
public static float CalculateRotationalEnergy(float inertia, float omega)
|
|
{
|
|
return 0.5f * inertia * omega * omega;
|
|
}
|
|
|
|
// Calculate omega from energy: ω = sqrt(2E / I)
|
|
public static float CalculateOmegaFromEnergy(float energy, float inertia)
|
|
{
|
|
if (energy <= 0) return 0;
|
|
return MathF.Sqrt(2f * energy / inertia);
|
|
}
|
|
|
|
public const float RAD_PER_SEC_TO_RPM = 60f / (2f * MathF.PI); // ≈ 9.549
|
|
public const float RPM_TO_RAD_PER_SEC = (2f * MathF.PI) / 60f; // ≈ 0.1047
|
|
}
|
|
}
|