1
0
Fork 0
flutter_demo_energy/lib/algorithms/energy.dart

30 lines
1.0 KiB
Dart
Raw Permalink Normal View History

2023-02-14 08:06:33 +01:00
/// free fall acceleration in m/s²
2023-04-12 08:41:41 +02:00
const double _g = 9.81;
2023-02-14 08:06:33 +01:00
///
/// Potential Energy = [mass] * [height] * g
/// with [mass] in kg, [height] in m and result in m²kg/s² = Joule
double potential(double mass, double height) {
2023-04-12 08:41:41 +02:00
return mass * height * _g;
2023-02-14 08:06:33 +01:00
}
double freedPotential(double mass, double hStart, double hEnd) {
return potential(mass, hStart) - potential(mass, hEnd);
}
///
/// Kinetic energy = 0.5 [mass] * [velocity] * [velocity]
/// with [mass] in kg and velocity in m/s and result in m²kg/s² = Joule
double kinetic(double mass, double velocity) {
return mass * velocity * velocity / 2;
}
double freedKinetic(double mass, double vStart, double vEnd) {
return kinetic(mass, vStart) - kinetic(mass, vEnd);
}
///
/// Amount of freed energy when an object changes its height from [hStart] m to [hEnd] m
/// and changes its velocity from [vStart] m/s² to [vEnd] m/s².
double freedEnergy(double mass, double hStart, double hEnd, double vStart, double vEnd) {
return freedPotential(mass, hStart, hEnd) + freedKinetic(mass, vStart, vEnd);
}