mpri-graphics-project/spheroid.cpp

57 lines
1.3 KiB
C++
Raw Normal View History

/**
* Implementation of a spheroid
**/
#include "spheroid.hpp"
2018-02-13 01:02:58 +01:00
#include <iostream>
2018-02-12 18:45:35 +01:00
Spheroid::Spheroid(const Point& _center, double _min_p, double _p, double _q) :
2018-02-13 18:06:01 +01:00
ImplicitSurface(_center), min_p(_min_p),
2018-02-12 18:45:35 +01:00
init_p(_p), p(_p), q(_q), stiffness(0)
{
_compute_volume();
}
void Spheroid::_compute_volume() {
2018-02-13 10:49:12 +01:00
V = (4./3.) * PI * p * q * q;
}
void Spheroid::update_radius() {
2018-02-13 01:02:58 +01:00
q = sqrt((3./4.) * V / PI / p);
}
void Spheroid::update_center_pos(Point& _center) {
center = _center;
}
2018-02-13 17:05:49 +01:00
void Spheroid::check_ground_collision(const Ground* ground) {
double height = (*ground)(center.x, center.z);
if (((center.y -p) <= height) || (p < init_p)) {
p = fmin(init_p, center.y - height);
update_radius();
}
}
Cuboid Spheroid::max_bounding_box() const {
double max_radius = sqrt((3./4.) * V / PI / min_p);
double max_height = init_p;
2018-02-13 16:13:03 +01:00
Point _bd1(max_radius, max_height, max_radius);
Point _bd2(-max_radius, -max_height, -max_radius);
return Cuboid(_bd1, _bd2);
}
2018-02-12 18:32:58 +01:00
2018-02-12 14:15:30 +01:00
double Spheroid::operator() (double _x, double _y, double _z) const {
return (pow(_x, 2) / pow(q, 2)
2018-02-13 01:02:58 +01:00
+ pow(_y, 2) / pow(p, 2)
+ pow(_z, 2) / pow(q, 2) -1);
2018-02-12 18:32:58 +01:00
}
Point Spheroid::location_hint() const {
return Point(0, p, 0);
}