2018-02-07 15:07:59 +01:00
|
|
|
/**
|
|
|
|
* Implementation of a spheroid
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "spheroid.hpp"
|
|
|
|
|
2018-02-12 14:31:08 +01:00
|
|
|
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) {
|
2018-02-07 15:07:59 +01:00
|
|
|
_compute_volume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spheroid::_compute_volume() {
|
|
|
|
V = (4/3) * PI * p * q * q;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Spheroid::update_radius() {
|
|
|
|
q = sqrt((3/4) * V / PI / p);
|
|
|
|
}
|
|
|
|
|
2018-02-11 17:29:56 +01:00
|
|
|
void Spheroid::update_height() {
|
|
|
|
q = (3/4) * V / PI / (p*p);
|
|
|
|
}
|
|
|
|
|
2018-02-07 15:07:59 +01:00
|
|
|
|
|
|
|
void Spheroid::update_center_pos(Point& _center) {
|
|
|
|
center = _center;
|
|
|
|
}
|
2018-02-09 20:23:06 +01:00
|
|
|
|
2018-02-11 17:29:56 +01:00
|
|
|
void Spheroid::check_horizontal_plan_collision(double& height) {
|
2018-02-09 20:23:06 +01:00
|
|
|
if ((center.z - p) <= height) {
|
2018-02-12 12:08:50 +01:00
|
|
|
p = fmin(init_p, center.z-height);
|
2018-02-09 20:23:06 +01:00
|
|
|
update_radius();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-11 17:29:56 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 14:31:08 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|