71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <J3ML/Geometry.h>
|
|
#include <J3ML/LinearAlgebra/Matrix3x3.h>
|
|
#include <J3ML/LinearAlgebra/Matrix4x4.h>
|
|
#include <J3ML/Geometry/LineSegment.h>
|
|
#include <J3ML/Geometry/TriangleMesh.h>
|
|
#include <J3ML/Geometry/Shape.h>
|
|
|
|
namespace J3ML::Geometry
|
|
{
|
|
using J3ML::LinearAlgebra::Matrix3x3;
|
|
using J3ML::LinearAlgebra::Matrix4x4;
|
|
|
|
// A mathematical representation of a 3-dimensional sphere
|
|
class Sphere : public Shape
|
|
{
|
|
public:
|
|
Vector3 Position;
|
|
float Radius;
|
|
Sphere() {}
|
|
Sphere(const Vector3& pos, float radius) : Position(pos), Radius(radius) {}
|
|
void Translate(const Vector3& offset)
|
|
{
|
|
Position = Position + offset;
|
|
}
|
|
void Transform(const Matrix3x3& transform)
|
|
{
|
|
Position = transform * Position;
|
|
}
|
|
void Transform(const Matrix4x4& transform)
|
|
{
|
|
Position = transform * Position;
|
|
}
|
|
inline float Cube(float inp) const
|
|
{
|
|
return inp*inp*inp;
|
|
}
|
|
float Volume() const
|
|
{
|
|
return 4.f * M_PI * Cube(Radius) / 3.f;
|
|
}
|
|
float SurfaceArea() const
|
|
{
|
|
return 4.f * M_PI * Cube(Radius) / 3.f;
|
|
}
|
|
bool IsFinite() const
|
|
{
|
|
return Position.IsFinite() && std::isfinite(Radius);
|
|
}
|
|
bool IsDegenerate()
|
|
{
|
|
return !(Radius > 0.f) || !Position.IsFinite();
|
|
}
|
|
bool Contains(const Vector3& point) const
|
|
{
|
|
return Position.DistanceSquared(point) <= Radius*Radius;
|
|
}
|
|
bool Contains(const Vector3& point, float epsilon) const
|
|
{
|
|
return Position.DistanceSquared(point) <= Radius*Radius + epsilon;
|
|
}
|
|
bool Contains(const LineSegment& lineseg) const
|
|
{
|
|
|
|
}
|
|
TriangleMesh GenerateUVSphere() const {}
|
|
TriangleMesh GenerateIcososphere() const {}
|
|
|
|
};
|
|
} |