1
/////////////////////////////////////////////////////////////
3
// Copyright (c) 2007-2011 by The University of Queensland //
4
// Earth Systems Science Computational Centre (ESSCC) //
5
// http://www.uq.edu.au/esscc //
7
// Primary Business: Brisbane, Queensland, Australia //
8
// Licensed under the Open Software License version 3.0 //
9
// http://www.opensource.org/licenses/osl-3.0.php //
11
/////////////////////////////////////////////////////////////
13
#include "ConvexPolyhedron.h"
15
ConvexPolyhedron::ConvexPolyhedron()
19
Construct polyhedron - without planes its just a box
21
\param pmin minimum point of bounding box
22
\param pmax maximum point of bounding box
24
ConvexPolyhedron::ConvexPolyhedron(const Vector3& pmin,const Vector3& pmax)
25
: BoxWithPlanes3D(pmin,pmax)
28
ConvexPolyhedron::~ConvexPolyhedron()
32
get point inside the box. The Argument is ignored
34
Vector3 ConvexPolyhedron::getAPoint(int)const
39
// std::cout << m_pmin << " - " << m_pmax << std::endl;
41
px=m_random(m_pmin.x(),m_pmax.x());
42
py=m_random(m_pmin.y(),m_pmax.y());
43
pz=m_random(m_pmin.z(),m_pmax.z());
44
res=Vector3(px,py,pz);
50
check if point is inside
54
bool ConvexPolyhedron::isIn(const Vector3& p) const
57
// std::cout << p << std::endl;
58
// check inside bounding box
59
res= ((p.x()>m_pmin.x()) && (p.x()<m_pmax.x()) &&
60
(p.y()>m_pmin.y()) && (p.y()<m_pmax.y()) &&
61
(p.z()>m_pmin.z()) && (p.z()<m_pmax.z()));
63
// std::cout << "inside bbx : " << res << std::endl;
64
// if inside, check against planes
66
vector<Plane>::const_iterator iter=m_planes.begin();
68
while((iter!=m_planes.end()) && (res)){
69
Vector3 normal=iter->getNormal();
70
Vector3 pdist=p-(iter->getOrig());
79
check if a Sphere is inside and doesn't intersect any planes
83
bool ConvexPolyhedron::isIn(const Sphere& S)
90
// std::cout << "rad: " << r << " pos: " << p << std::endl;
92
res=(p.X()>m_pmin.X()+r) && (p.X()<m_pmax.X()-r) &&
93
(p.Y()>m_pmin.Y()+r) && (p.Y()<m_pmax.Y()-r) &&
94
(p.Z()>m_pmin.Z()+r) && (p.Z()<m_pmax.Z()-r);
96
// if inside, check against planes
98
vector<Plane>::const_iterator iter=m_planes.begin();
100
while((iter!=m_planes.end()) && (res)){
101
Vector3 normal=iter->getNormal();
102
Vector3 pdist=p-(iter->getOrig());
103
res=(normal*pdist>r);