/** * Implementation of a spheroid **/ #include "spheroid.hpp" Spheroid::Spheroid(const Point& _center, double _p, double _q) : ImplicitSurface(_center), init_p(_p), 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_height() { q = (3/4) * V / PI / (p*p); } void Spheroid::update_center_pos(Point& _center) { center = _center; } void Spheroid::check_horizontal_plan_collision(double& height) { if ((center.z - p) <= height) { p = fmin(init_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(); } } }