From 22e24258cdadb6a3cb4cc3958dce62dcfbbe8ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Sun, 11 Feb 2018 17:29:56 +0100 Subject: [PATCH] Add a vertical plan collision --- spheroid.cpp | 19 ++++++++++++++++++- spheroid.hpp | 4 +++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/spheroid.cpp b/spheroid.cpp index 39b77e6..e66cfc5 100644 --- a/spheroid.cpp +++ b/spheroid.cpp @@ -22,15 +22,32 @@ void Spheroid::update_radius() { q = sqrt((3/4) * V / PI / p); } +void Spheroid::update_height() { + q = (3/4) * V / PI / (p*p); +} + void Spheroid::update_center_pos(Point& _center) { center = _center; } -void Spheroid::check_plan_collision(double& height) { +void Spheroid::check_horizontal_plan_collision(double& height) { if ((center.z - p) <= height) { p = center.z-height; update_radius(); } } +void Spheroid::check_vertical_plan_collision(double& abscissa) { + if (center.x <= abscissa) { + if ((center.x + q) >= abscissa) { + q = abscissa - center.x; + update_height(); + } + } else { + if ((center.x - q) <= abscissa) { + q = center.x - abscissa; + update_height(); + } + } +} diff --git a/spheroid.hpp b/spheroid.hpp index 93a647a..18a782a 100644 --- a/spheroid.hpp +++ b/spheroid.hpp @@ -15,8 +15,10 @@ class Spheroid : public ImplicitSurface { Spheroid(Point& _center, 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_plan_collision(double& height); + void check_horizontal_plan_collision(double& height); + void check_vertical_plan_collision(double& abscissa); double operator() (double _x, double _y, double _z) { return (pow(_x - center.x, 2) / pow(q, 2) + pow(_y - center.y, 2) / pow(q, 2)