From 1ee6875b5a945afc4a89fa972ac352efc0d93626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Mon, 12 Feb 2018 14:31:08 +0100 Subject: [PATCH] Bounding box for spheroid, based on initial values. --- Ball.cpp | 2 +- spheroid.cpp | 15 ++++++++++----- spheroid.hpp | 7 +++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Ball.cpp b/Ball.cpp index 82338a4..f5b8933 100644 --- a/Ball.cpp +++ b/Ball.cpp @@ -4,7 +4,7 @@ Ball::Ball(Point& _center, double _min_height, double _v_x, double _p, double _q) : Center(_center), - surface(_center, _p, _q), + surface(_center, min_height, _p, _q), init_h(_center.z), min_height(_min_height), bounce_number(0.0), diff --git a/spheroid.cpp b/spheroid.cpp index ef9f381..7fb8673 100644 --- a/spheroid.cpp +++ b/spheroid.cpp @@ -4,8 +4,8 @@ #include "spheroid.hpp" -Spheroid::Spheroid(Point& _center, size_t _p, size_t _q) : - ImplicitSurface(_center), init_p(_p), p(_p), q(_q), stiffness(0) { +Spheroid::Spheroid(Point& _center, double _min_p, size_t _p, size_t _q) : + ImplicitSurface(_center), min_p(_min_p), init_p(_p), p(_p), q(_q) { _compute_volume(); } @@ -13,9 +13,6 @@ void Spheroid::_compute_volume() { V = (4/3) * PI * p * q * q; } -void Spheroid::set_stiffness(size_t _stiffness) { - stiffness = _stiffness; -} void Spheroid::update_radius() { @@ -51,3 +48,11 @@ void Spheroid::check_vertical_plan_collision(double& abscissa) { } } } + +Cuboid Spheroid::max_bounding_box() const { + double max_radius = sqrt((3/4) * V / PI / min_p); + double max_height = init_p; + Point _bd1(max_radius, max_radius, max_height); + Point _bd2(-max_radius, -max_radius, -max_height); + return Cuboid(_bd1, _bd2); +} diff --git a/spheroid.hpp b/spheroid.hpp index 66b2aec..eb0128d 100644 --- a/spheroid.hpp +++ b/spheroid.hpp @@ -12,13 +12,13 @@ const double PI = 3.141592653589793; class Spheroid : public ImplicitSurface { public: - Spheroid(Point& _center, size_t _p, size_t _q); + Spheroid(Point& _center, double _min_p, size_t _p, size_t _q); void update_center_pos(Point& _center); void update_radius(); void update_height(); - void set_stiffness(size_t _stiffness); void check_horizontal_plan_collision(double& height); void check_vertical_plan_collision(double& abscissa); + Cuboid max_bounding_box() const; double operator() (double _x, double _y, double _z) const { return (pow(_x - center.x, 2) / pow(q, 2) + pow(_y - center.y, 2) / pow(q, 2) @@ -31,8 +31,7 @@ class Spheroid : public ImplicitSurface { * V is the volume. Extremely useful to have a constant volume in the * ball **/ - double init_p, p, q; - size_t stiffness; + double min_p, init_p, p, q; double V; void _compute_volume(); };