|
// BoundingBox.cpp: implementation of the CBoundingBox class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BoundingBox.h"
#include "Point3D.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBoundingBox::CBoundingBox()
{
}
CBoundingBox::CBoundingBox(const double& xMin, const double& xMax,
const double& yMin, const double& yMax,
const double& zMin, const double& zMax) : itsXMax(xMax), itsXMin(xMin),
itsYMax(yMax), itsYMin(yMin),
itsZMax(zMax), itsZMin(zMin)
{
}
CBoundingBox::~CBoundingBox()
{
}
CPoint3D CBoundingBox::Center() const
{
CPoint3D P;
P.SetX((XMax() + XMin())/2);
P.SetY((YMax() + YMin())/2);
P.SetZ((ZMax() + ZMin())/2);
return P;
}
double CBoundingBox::BoundingRadius() const
{
double rad;
CPoint3D Pmax(XMax(), YMax(), ZMax());
CPoint3D Cen = Center();
rad = Pmax.Distance(Cen);
return rad;
}
void CBoundingBox::SetLimits(const double& xMin, const double& xMax,
const double& yMin, const double& yMax,
const double& zMin, const double& zMax)
{
itsXMax = xMax;
itsXMin = xMin;
itsYMax = yMax;
itsYMin = yMin;
itsZMax = zMax;
itsZMin = zMin;
}
bool CBoundingBox::Contains(const CPoint3D& P) const
{
bool bx = false, by = false, bz = false;
bx = (P.GetX() <= XMax() && P.GetX() >= XMin());
by = (P.GetY() <= YMax() && P.GetY() >= YMin());
bz = (P.GetZ() <= ZMax() && P.GetZ() >= ZMin());
return (bx && by &&bz);
}
void CBoundingBox::AddBox(const CBoundingBox& B)
{
if(B.XMax() > XMax())
itsXMax = B.XMax();
if(B.XMin() < XMin())
itsXMin = B.XMin();
if(B.YMax() > YMax())
itsYMax = B.YMax();
if(B.YMin() < YMin())
itsYMin = B.YMin();
if(B.ZMax() > ZMax())
itsZMax = B.ZMax();
if(B.ZMin() < ZMin())
itsZMin = B.ZMin();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.