cpd_2022_energy/lib/models/EnergyBilanceModel.dart

46 lines
952 B
Dart
Raw Normal View History

2022-11-07 18:52:21 +01:00
import 'dart:math';
import 'package:flutter/material.dart';
class EnergyBilanceModel extends ChangeNotifier {
double _startVelocity = 0;
double _endVelocity = 0;
double _startHeight = 0;
double _endHeight = 0;
double _weight = 0;
static const double _gravity = 9.81; //in m/s^2
double get deltaVelocity => _endVelocity - _startVelocity;
double get deltaHeight => _endHeight - _startHeight;
double get potentialEnergy => _weight * _gravity * deltaHeight;
double get kineticEnergy => _weight * pow(deltaVelocity, 2) / 2;
void setStartVelocity(double v){
_startVelocity = v;
notifyListeners();
}
void setEndVelocity(double v){
_endVelocity = v;
notifyListeners();
}
void setStartHeight(double h){
_startHeight = h;
notifyListeners();
}
void setEndHeight(double h){
_endHeight = h;
notifyListeners();
}
void setWeight(double m){
_weight = m;
notifyListeners();
}
}