Skip to content
Snippets Groups Projects
Commit 8a0a451a authored by Karsten Rink's avatar Karsten Rink
Browse files

renamed distance method, changed initialisation list, fixed issue with volume calculation

parent fb3993cf
No related branches found
No related tags found
No related merge requests found
......@@ -255,7 +255,7 @@ double calcTetrahedronVolume(const double* x1, const double* x2, const double* x
const MathLib::Vector3 ab(x1, x2);
const MathLib::Vector3 ac(x1, x3);
const MathLib::Vector3 ad(x1, x4);
return GeoLib::scalarTriple(ab, ac, ad) / 6.0;
return std::abs(GeoLib::scalarTriple(ac, ad, ab)) / 6.0;
}
// NewellPlane from book Real-Time Collision detection p. 494
......
......@@ -22,27 +22,33 @@
namespace GeoLib {
BoundingSphere::BoundingSphere()
: _center(std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()), _radius(-1)
: _radius(-1), _center(std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max())
{
}
BoundingSphere::BoundingSphere(BoundingSphere const& sphere)
: _center(sphere.getCenter()), _radius(sphere.getRadius())
: _radius(sphere.getRadius()), _center(sphere.getCenter())
{
}
BoundingSphere::BoundingSphere(BoundingSphere const&& sphere)
: _radius(sphere.getRadius()), _center(sphere.getCenter())
{
}
BoundingSphere::BoundingSphere(GeoLib::Point const& p)
: _center(p), _radius(std::numeric_limits<double>::epsilon())
: _radius(std::numeric_limits<double>::epsilon()), _center(p)
{
}
BoundingSphere::BoundingSphere(GeoLib::Point const& p, double radius)
: _center(p), _radius(radius)
: _radius(radius), _center(p)
{
}
BoundingSphere::BoundingSphere(GeoLib::Point const& p, GeoLib::Point const& q)
: _center(p), _radius(std::numeric_limits<double>::epsilon())
: _radius(std::numeric_limits<double>::epsilon()), _center(p)
{
MathLib::Vector3 const a(p, q);
......@@ -164,7 +170,7 @@ BoundingSphere BoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> sp
for(std::size_t i=0; i<length; ++i)
{
// current point is located outside of sphere
if (sphere.sqrPointDist(*sphere_points[start_idx+i]) > 0)
if (sphere.pointDistanceSquared(*sphere_points[start_idx+i]) > 0)
{
if (i>start_idx)
{
......@@ -178,7 +184,7 @@ BoundingSphere BoundingSphere::recurseCalculation(std::vector<GeoLib::Point*> sp
return sphere;
}
double BoundingSphere::sqrPointDist(GeoLib::Point const& pnt) const
double BoundingSphere::pointDistanceSquared(GeoLib::Point const& pnt) const
{
return MathLib::sqrDist(_center.getCoords(), pnt.getCoords())-(_radius*_radius);
}
......
......@@ -31,6 +31,8 @@ public:
BoundingSphere();
/// Copy constructor
BoundingSphere(BoundingSphere const& sphere);
/// Move constructor
BoundingSphere(BoundingSphere const&& sphere);
/// Point-Sphere
BoundingSphere(GeoLib::Point const& p);
/// Constructor using center and radius
......@@ -51,10 +53,10 @@ public:
/// Returns the radius of the sphere
double getRadius() const {return _radius; }
/// Returns the squared distance of a point from the sphere (for points within the sphere distance is negative)
double sqrPointDist(GeoLib::Point const& pnt) const;
/// Returns the squared euclidean distance of a point from the sphere (for points within the sphere distance is negative)
double pointDistanceSquared(GeoLib::Point const& pnt) const;
/// Creates n_points random points located on the surface of the sphere (useful for visualisation)
/// Creates n_points random points located on the surface of the bounding sphere (useful for visualisation)
std::vector<GeoLib::Point*>* getRandomSpherePoints(std::size_t n_points) const;
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment