From dae55f5eabbf586833c88d6b145c55a6faa95636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Wed, 31 Jan 2018 16:43:53 +0100 Subject: [PATCH] Rough implementation of an ellipsoid. In an extremely simple model, the ball will deform as an ellipsoid during the bounce process. --- ellipsoid.cpp | 18 ++++++++++++++++++ ellipsoid.hpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 ellipsoid.cpp create mode 100644 ellipsoid.hpp diff --git a/ellipsoid.cpp b/ellipsoid.cpp new file mode 100644 index 0000000..7b43416 --- /dev/null +++ b/ellipsoid.cpp @@ -0,0 +1,18 @@ +/** + * Implementation of an ellipsoid + **/ + +#include "ellipsoid.hpp" + +Ellipsoid::Ellipsoid(Point& _center, size_t _p, size_t _q) : + center(_center), p(_p), q(_q), stiffness(0) { + _compute_volume(); + } + +void Ellipsoid::_compute_volume() { + V = (4/3) * PI * p * q * q; +} + +void Ellipsoid::set_stiffness(size_t _stiffness) { + stiffness = _stiffness; +} diff --git a/ellipsoid.hpp b/ellipsoid.hpp new file mode 100644 index 0000000..f4eea39 --- /dev/null +++ b/ellipsoid.hpp @@ -0,0 +1,30 @@ +/** + * Defines an ellispoid, which is a basic interpretaion of the ball when it is + * bouncing. + **/ + +#include +#include "Implicit.hpp" +#include "common_structures.hpp" + +const double PI = 3.141592653589793; + +class Ellipsoid : public ImplicitSurface { + public: + Ellipsoid(Point& _center, size_t _p, size_t _q); + void update_center_pos(size_t dt); + void set_stiffness(size_t _stiffness); + private: + /** + * p corresponds to the half-height of the ball, + * q to the radius of the ball, + * V is the volume. Extremely useful to have a constant volume in the + * ball + **/ + size_t stiffness; + size_t p, q; + double V; + Point& center; + void _compute_volume(); + void _compute_pos(size_t t); +};