Files
core_math/tjp/core/math/Sphere3.hpp
Timothy Prepscius 0807c0286a flatten 20260225
2026-02-25 12:36:47 -05:00

79 lines
1.6 KiB
C++
Executable File

//
// Math.hpp
// amoeba
//
// Created by Timothy Prepscius on 12/30/16.
// Copyright © 2016 Timothy Prepscius. All rights reserved.
//
#pragma once
#include "Sphere3.h"
#include "Zero.h"
#include <tjp/core/types/Types.h>
#include <limits>
#include "Vector3.hpp"
#include <tjp/core/containers/Vector.hpp>
namespace tjp {
namespace core {
namespace math {
template<typename Real>
class Sphere3
{
public:
typedef Real value_type;
typedef Vector3<Real> Center;
Center center;
Real radius;
Sphere3 () {}
Sphere3 (const Vector3<Real> &center_, Real radius_) :
center(center_),
radius(radius_)
{
}
Real distanceTo(const Vector3<Real> &p) const;
Real minDistanceTo (const Sphere3<Real> &v) const;
Real maxDistanceTo (const Sphere3<Real> &v) const;
Real minDistanceTo (const Vector3<Real> &v) const;
Real maxDistanceTo (const Vector3<Real> &v) const;
bool contains(const Vector3<Real> &p) const;
bool contains(const Sphere3<Real> &v) const;
const static Sphere3 Zero;
const static Sphere3 Infinite;
template<typename T>
Sphere3<T> asType() const
{
return Sphere3<T> { center.template asType<T>(), T(radius) };
}
};
template<typename Real>
const Sphere3<Real> Sphere3<Real>::Zero = { Vector3<Real>::Zero, 0 };
template<typename Real>
const Sphere3<Real> Sphere3<Real>::Infinite = { Vector3<Real>::Zero, std::numeric_limits<Real>::infinity() };
typedef Sphere3<float> Sphere3f;
typedef Sphere3<double> Sphere3d;
typedef Sphere3<Real> Sphere3r;
Sphere3r minimumBoundingSphere(const Vector<math::Vector3r> &points);
} // namespace
} // namespace
} // namespace