From e76974204def00648885b7771014b37b8f42b033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Oudin?= Date: Wed, 7 Feb 2018 15:07:59 +0100 Subject: [PATCH] s/ellipsoid/spheroid + implementation of operator() --- ellipsoid.cpp | 18 ------------------ spheroid.cpp | 28 ++++++++++++++++++++++++++++ ellipsoid.hpp => spheroid.hpp | 16 +++++++++++----- 3 files changed, 39 insertions(+), 23 deletions(-) delete mode 100644 ellipsoid.cpp create mode 100644 spheroid.cpp rename ellipsoid.hpp => spheroid.hpp (57%) diff --git a/ellipsoid.cpp b/ellipsoid.cpp deleted file mode 100644 index 7b43416..0000000 --- a/ellipsoid.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/** - * 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/spheroid.cpp b/spheroid.cpp new file mode 100644 index 0000000..37089d7 --- /dev/null +++ b/spheroid.cpp @@ -0,0 +1,28 @@ +/** + * Implementation of a spheroid + **/ + +#include "spheroid.hpp" + +Spheroid::Spheroid(Point& _center, size_t _p, size_t _q) : + center(_center), p(_p), q(_q), stiffness(0) { + _compute_volume(); + } + +void Spheroid::_compute_volume() { + V = (4/3) * PI * p * q * q; +} + +void Spheroid::set_stiffness(size_t _stiffness) { + stiffness = _stiffness; +} + + +void Spheroid::update_radius() { + q = sqrt((3/4) * V / PI / p); +} + + +void Spheroid::update_center_pos(Point& _center) { + center = _center; +} diff --git a/ellipsoid.hpp b/spheroid.hpp similarity index 57% rename from ellipsoid.hpp rename to spheroid.hpp index f4eea39..ae6c80b 100644 --- a/ellipsoid.hpp +++ b/spheroid.hpp @@ -4,16 +4,23 @@ **/ #include +#include #include "Implicit.hpp" #include "common_structures.hpp" const double PI = 3.141592653589793; -class Ellipsoid : public ImplicitSurface { +class Spheroid : public ImplicitSurface { public: - Ellipsoid(Point& _center, size_t _p, size_t _q); - void update_center_pos(size_t dt); + Spheroid(Point& _center, size_t _p, size_t _q); + void update_center_pos(Point& _center); + void update_radius(); void set_stiffness(size_t _stiffness); + 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) + + pow(_z - center.z, 2) / pow(p, 2) -1); + } private: /** * p corresponds to the half-height of the ball, @@ -22,9 +29,8 @@ class Ellipsoid : public ImplicitSurface { * ball **/ size_t stiffness; - size_t p, q; + double p, q; double V; Point& center; void _compute_volume(); - void _compute_pos(size_t t); };