From dfbaa80e030fb9c5d527c1fd9d40058088acf4e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Mon, 12 Feb 2018 10:21:49 +0100 Subject: [PATCH] Debug of the physical model --- Ball.cpp | 24 ++++++++++++++++-------- Ball.hpp | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Ball.cpp b/Ball.cpp index a2e3705..f3f522e 100644 --- a/Ball.cpp +++ b/Ball.cpp @@ -6,12 +6,12 @@ Ball::Ball(Point& _center, double _v_x, double _p, double _q) : Center(_center), surface(_center, _p, _q), init_h(_center.z), - bounce_number(0), + bounce_number(0.0), crt_time(0), A(_center.z), B(0), U(sqrt(2 * G_CTE * _center.z)), - T(0), + T(sqrt(2.0 * _center.z / G_CTE)), v_x(_v_x) { } @@ -23,8 +23,8 @@ void Ball::_compute_pos(double dt) { } void Ball::_compute_T_n() { - double swap = T; - T = swap + 2/G_CTE * pow(1/2, bounce_number - 2) * sqrt(2 * init_h / G_CTE); + double update = (pow(0.5, bounce_number-1) * sqrt(2 * init_h / G_CTE)); + T += update; } void Ball::_compute_B_n() { B = G_CTE * T + U; @@ -35,29 +35,37 @@ void Ball::_compute_A_n() { } void Ball::_compute_U_n() { - U *= 1/2; + U *= 0.5; } void Ball::_compute_v_x() { - v_x *= 1/2; + v_x *= 0.5; } void Ball::update_pos(double dt) { crt_time += dt; if (crt_time >= T) { - _compute_T_n(); + bounce_number += 1; _compute_U_n(); _compute_A_n(); _compute_B_n(); + _compute_T_n(); _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); } std::ostream& operator<< (std::ostream &out, Ball const& data) { Point center = data.getCenter(); + out << "t:" << data.access_crt_time() << ":"; + out << "T:" << data.accessT() << ":"; out << center.x << ':'; out << center.y << ':'; - out << center.z << '\n'; + out << center.z << ':'; return out; } diff --git a/Ball.hpp b/Ball.hpp index 39a3dd0..f1df10e 100644 --- a/Ball.hpp +++ b/Ball.hpp @@ -34,6 +34,8 @@ class Ball { Ball(Point& _center, double _v_x, double p, double q); void update_pos(double dt); 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);