#pragma region CPL License
/*
Nuclex Native Framework
Copyright (C) 2002-2015 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#pragma endregion // CPL License
#ifndef NUCLEX_GEOMETRY_VOLUMES_SPHERE3_H
#define NUCLEX_GEOMETRY_VOLUMES_SPHERE3_H
#include "Nuclex/Geometry/Point3.h"
#include "Nuclex/Geometry/Math.h"
#include "Nuclex/Geometry/Volumes/Box3.h"
namespace Nuclex { namespace Geometry { namespace Volumes {
// ------------------------------------------------------------------------------------------- //
/// Sphere in 3D space stored as a position and a radius
template
struct Sphere3 {
/// A unit sphere located at the center of the coordinate system
public: static const Sphere3 Unit;
/// Initializes a sphere using the specified position and radius
/// Position of the sphere's center point
/// Radius of the sphere
public: Sphere3(const Point3 ¢er, TScalar radius) :
Center(center), Radius(radius) {}
/// Calculates the surface area of the sphere
/// The surface area of the sphere
public: TScalar GetArea() const {
return Math::Pi * 4 * (this->Radius * this->Radius);
}
/// Calculates the volume of the sphere
/// The volume of the sphere
public: TScalar GetVolume() const {
return Math::Pi * 4 * (this->Radius * this->Radius * this->Radius) / 3;
}
/// Returns the center of the sphere
/// The center of the sphere
///
/// Provided for consistency when accessing the volume via template code.
/// Use the public field when working with the Sphere3
/// class directly.
///
public: Point3 GetCenter() const {
return this->Center;
}
/// Offsets the entire sphere by the specified amount
/// Amount the sphere will be offset on the X axis
/// Amount the sphere will be offset on the Y axis
/// Amount the sphere will be offset on the Z axis
public: void ShiftBy(TScalar amountX, TScalar amountY, TScalar amountZ) {
this->Center.X += amountX;
this->Center.Y += amountY;
this->Center.Z += amountZ;
}
/// Offsets the entire sphere by the specified amount
/// Amount the sphere will be offset
public: void ShiftBy(const Vector3 &amount) {
this->Center += amount;
}
/// Coordinates of the sphere's center
public: Point3 Center;
/// Radius of the sphere
public: TScalar Radius;
};
// ------------------------------------------------------------------------------------------- //
template
const Sphere3 Sphere3::Unit(Point3::Zero, 1);
// ------------------------------------------------------------------------------------------- //
}}} // namespace Nuclex::Geometry::Volumes
#endif // NUCLEX_GEOMETRY_VOLUMES_SPHERE3_H