Debug of the physical model

This commit is contained in:
Rémi Oudin 2018-02-12 10:21:49 +01:00
parent d600f51a3a
commit dfbaa80e03
2 changed files with 18 additions and 8 deletions

View file

@ -6,12 +6,12 @@ Ball::Ball(Point& _center, double _v_x, double _p, double _q) :
Center(_center), Center(_center),
surface(_center, _p, _q), surface(_center, _p, _q),
init_h(_center.z), init_h(_center.z),
bounce_number(0), bounce_number(0.0),
crt_time(0), crt_time(0),
A(_center.z), A(_center.z),
B(0), B(0),
U(sqrt(2 * G_CTE * _center.z)), U(sqrt(2 * G_CTE * _center.z)),
T(0), T(sqrt(2.0 * _center.z / G_CTE)),
v_x(_v_x) v_x(_v_x)
{ {
} }
@ -23,8 +23,8 @@ void Ball::_compute_pos(double dt) {
} }
void Ball::_compute_T_n() { void Ball::_compute_T_n() {
double swap = T; double update = (pow(0.5, bounce_number-1) * sqrt(2 * init_h / G_CTE));
T = swap + 2/G_CTE * pow(1/2, bounce_number - 2) * sqrt(2 * init_h / G_CTE); T += update;
} }
void Ball::_compute_B_n() { void Ball::_compute_B_n() {
B = G_CTE * T + U; B = G_CTE * T + U;
@ -35,29 +35,37 @@ void Ball::_compute_A_n() {
} }
void Ball::_compute_U_n() { void Ball::_compute_U_n() {
U *= 1/2; U *= 0.5;
} }
void Ball::_compute_v_x() { void Ball::_compute_v_x() {
v_x *= 1/2; v_x *= 0.5;
} }
void Ball::update_pos(double dt) { void Ball::update_pos(double dt) {
crt_time += dt; crt_time += dt;
if (crt_time >= T) { if (crt_time >= T) {
_compute_T_n(); bounce_number += 1;
_compute_U_n(); _compute_U_n();
_compute_A_n(); _compute_A_n();
_compute_B_n(); _compute_B_n();
_compute_T_n();
_compute_v_x(); _compute_v_x();
std::cout << "New bounce :";
std::cout << "U:" << U << ":";
std::cout << "A:" << A << ":";
std::cout << "B:" << B << ":";
std::cout << "T:" << T << "\n";
} }
_compute_pos(dt); _compute_pos(dt);
} }
std::ostream& operator<< (std::ostream &out, Ball const& data) { std::ostream& operator<< (std::ostream &out, Ball const& data) {
Point center = data.getCenter(); Point center = data.getCenter();
out << "t:" << data.access_crt_time() << ":";
out << "T:" << data.accessT() << ":";
out << center.x << ':'; out << center.x << ':';
out << center.y << ':'; out << center.y << ':';
out << center.z << '\n'; out << center.z << ':';
return out; return out;
} }

View file

@ -34,6 +34,8 @@ class Ball {
Ball(Point& _center, double _v_x, double p, double q); Ball(Point& _center, double _v_x, double p, double q);
void update_pos(double dt); void update_pos(double dt);
Point getCenter() const {return Center;} Point getCenter() const {return Center;}
double accessT() const { return T;}
double access_crt_time() const { return crt_time;}
}; };
std::ostream& operator << (std::ostream &out, Ball const& data); std::ostream& operator << (std::ostream &out, Ball const& data);