1 #ifndef _GeoPrimitives_H_
7 #define _GeoPrimitives_H_
17 const double TOL = 1e-16;
32 P[0] =
P[1] =
P[2] = 0.0;
34 CPoint(
double ix,
double iy,
double iz = 0.0)
87 return(
sqrt((
x()*
x()) + (
y()*
y()) + (
z()*
z())));
91 return( (fabs(
P[0] - p.
P[0]) <
TOL) &&
92 (fabs(
P[1] - p.
P[1]) <
TOL) &&
93 (fabs(
P[2] - p.
P[2]) <
TOL) );
97 return (!((*
this)==p));
143 double &
x(){
return P[0]; };
149 const double &
x()
const {
return P[0]; };
150 double &
y(){
return P[1]; };
156 const double &
y()
const {
return P[1]; };
157 double &
z(){
return P[2]; };
163 const double &
z()
const {
return P[2]; };
186 return((*
this - p).
norm());
213 V[0] =
V[1] =
V[2] = 0.;
223 V[0] = (p2 -
p1).
x();
224 V[1] = (p2 -
p1).
y();
225 V[2] = (p2 -
p1).
z();
275 V[0] = (p2 -
p1).
x();
276 V[1] = (p2 -
p1).
y();
277 V[2] = (p2 -
p1).
z();
282 V[0] =
V[1] =
V[2] = 0.0;
287 return(
sqrt((
V[0] *
V[0]) + (V[1] * V[1]) + (V[2] * V[2])));
295 return ((
V[0]*
V[0])+(V[1]*V[1])+(V[2]*V[2]));
316 return((
V[0] * v2.
V[0]) +
322 CVector rv(num*
V[0],num*V[1],num*V[2]);
335 v.
V[0] = ((v2.
V[2] *
V[1]) - (v2.
V[1] *
V[2]));
336 v.
V[1] = ((v2.
V[0] *
V[2]) - (v2.
V[2] *
V[0]));
337 v.
V[2] = ((v2.
V[1] *
V[0]) - (v2.
V[0] *
V[1]));
360 return(
copy((*
this)%v2));
369 return((*
this) + (-1.0 * v2));
387 return(
copy((*
this) - v2));
440 return( (fabs(
V[0] - v.
V[0]) <
TOL) &&
441 (fabs(
V[1] - v.
V[1]) <
TOL) &&
442 (fabs(
V[2] - v.
V[2]) <
TOL) );
454 return ( (*
this < v) ||
459 return ( (*
this > v) ||
480 V[0] =
V[1] =
V[2] = 0.;
564 V[0] =
V[1] =
V[2] = 0.0;
569 V[0] =
V[1] =
V[2] = 0.0;
574 return(
sqrt((
V[0] *
V[0]) + (V[1] * V[1]) + (V[2] * V[2])));
582 return ((
V[0]*
V[0])+(V[1]*V[1])+(V[2]*V[2]));
602 return((
V[0] * v2.
V[0]) +
627 v.
V[0] = ((v2.
V[2] *
V[1]) - (v2.
V[1] *
V[2]));
628 v.
V[1] = ((v2.
V[0] *
V[2]) - (v2.
V[2] *
V[0]));
629 v.
V[2] = ((v2.
V[1] *
V[0]) - (v2.
V[0] *
V[1]));
641 V[0] = ((v2.
V[2] * t1) - (v2.
V[1] * t2));
642 V[1] = ((v2.
V[0] * t2) - (v2.
V[2] * t0));
643 V[2] = ((v2.
V[1] * t0) - (v2.
V[0] * t1));
653 return((*
this) + (-1.0 * v2));
720 return( (fabs(
V[0] - v.
V[0]) <
TOL) &&
721 (fabs(
V[1] - v.
V[1]) <
TOL) &&
722 (fabs(
V[2] - v.
V[2]) <
TOL) );
734 return ( (*
this < v) ||
739 return ( (*
this > v) ||
1030 return( (p == l.
p) &&
1037 double r = v2 *
v.
unit();
1038 return( (fabs(r - 1.0) <
TOL) ||
1039 (fabs(r + 1.0) <
TOL) );
1065 :
p1(0,0,0),
p2(0,0,0)
1085 if(p3 ==
p1 || p3 ==
p2)
return true;
1086 if(
p1 ==
p2)
return false;
1092 else if(
p1.
y() !=
p2.
y())
1094 else if(
p1.
z() !=
p2.
z())
1096 return ( u >= 0.0 && u <= 1.0 );
1140 CBox(
const std::vector<CPoint> &pv)
1142 std::vector<CPoint>::const_iterator pvi = pv.begin();
1150 while(pvi != pv.end()){
1151 if(pvi->x() <
p1.
x())
p1.
x(pvi->x());
1152 if(pvi->x() >
p2.
x())
p2.
x(pvi->x());
1153 if(pvi->y() <
p1.
y())
p1.
y(pvi->y());
1154 if(pvi->y() >
p2.
y())
p2.
y(pvi->y());
1155 if(pvi->z() <
p1.
z())
p1.
z(pvi->z());
1156 if(pvi->z() >
p2.
z())
p2.
z(pvi->z());
1167 for(
unsigned int i = 1;
i<
n;
i++){
1168 if(points[
i*3] <
p1.
x())
p1.
x(points[
i*3]);
1169 if(points[i*3] >
p2.
x())
p2.
x(points[i*3]);
1170 if(points[(i*3)+1] <
p1.
y())
p1.
y(points[(i*3)+1]);
1171 if(points[(i*3)+1] >
p2.
y())
p2.
y(points[(i*3)+1]);
1172 if(points[(i*3)+2] <
p1.
z())
p1.
z(points[(i*3)+2]);
1173 if(points[(i*3)+2] >
p2.
z())
p2.
z(points[(i*3)+2]);
1197 for(
unsigned int i = 1;
i<
n;
i++){
1198 if(points[
i*3] <
p1.
x())
p1.
x(points[
i*3]);
1199 if(points[i*3] >
p2.
x())
p2.
x(points[i*3]);
1200 if(points[(i*3)+1] <
p1.
y())
p1.
y(points[(i*3)+1]);
1201 if(points[(i*3)+1] >
p2.
y())
p2.
y(points[(i*3)+1]);
1202 if(points[(i*3)+2] <
p1.
z())
p1.
z(points[(i*3)+2]);
1203 if(points[(i*3)+2] >
p2.
z())
p2.
z(points[(i*3)+2]);
1217 p.
y()-fabs(v.
y()/2.0),
1218 p.
z()-fabs(v.
z()/2.0));
1220 p.
y()+fabs(v.
y()/2.0),
1221 p.
z()+fabs(v.
z()/2.0));
1251 return( p.
x() <=
p2.
x() && p.
x() >=
p1.
x() &&
1252 p.
y() <=
p2.
y() && p.
y() >=
p1.
y() &&
1253 p.
z() <=
p2.
z() && p.
z() >=
p1.
z() );
1257 return( p[0] <=
p2.
x() && p[0] >=
p1.
x() &&
1258 p[1] <=
p2.
y() && p[1] >=
p1.
y() &&
1259 p[2] <=
p2.
z() && p[2] >=
p1.
z() );
1265 return(fabs(v.
x()*v.
y()*v.
z()));
1341 double A = p1.
y()*(p2.
z() - p3.
z()) + p2.
y()*(p3.
z() - p1.
z()) +
1342 p3.
y()*(p1.
z() - p2.
z());
1343 double B = p1.
z()*(p2.
x() - p3.
x()) + p2.
z()*(p3.
x() - p1.
x()) +
1344 p3.
z()*(p1.
x() - p2.
x());
1345 double C = p1.
x()*(p2.
y() - p3.
y()) + p2.
x()*(p3.
y() - p1.
y()) +
1346 p3.
x()*(p1.
y() - p2.
y());
1358 :
n(plane.
n),
p(plane.
p)
1363 double A = vec[0].y()*(vec[1].z() - vec[2].z()) +
1364 vec[1].
y()*(vec[2].z() - vec[0].z()) +
1365 vec[2].
y()*(vec[0].z() - vec[1].z());
1366 double B = vec[0].z()*(vec[1].x() - vec[2].x()) +
1367 vec[1].
z()*(vec[2].x() - vec[0].x()) +
1368 vec[2].
z()*(vec[0].x() - vec[1].x());
1369 double C = vec[0].x()*(vec[1].y() - vec[2].y()) +
1370 vec[1].
x()*(vec[2].y() - vec[0].y()) +
1371 vec[2].
x()*(vec[0].y() - vec[1].y());
1385 double A()
const {
return(
n.
x()); };
1386 double B()
const {
return(
n.
y()); };
1387 double C()
const {
return(
n.
z()); };
1390 return( -1.0 * (
n.
x()*
p.
x() +
n.
y()*
p.
y() +
n.
z()*
p.
z()));
1398 return(fabs(
n.
x()*P.
x() +
n.
y()*P.
y() +
n.
z()*P.
z() +
D()) <=
TOL);
1415 double A = p1.
y()*(p2.
z() - p3.
z()) + p2.
y()*(p3.
z() - p1.
z()) +
1416 p3.
y()*(p1.
z() - p2.
z());
1417 double B = p1.
z()*(p2.
x() - p3.
x()) + p2.
z()*(p3.
x() - p1.
x()) +
1418 p3.
z()*(p1.
x() - p2.
x());
1419 double C = p1.
x()*(p2.
y() - p3.
y()) + p2.
x()*(p3.
y() - p1.
y()) +
1420 p3.
x()*(p1.
y() - p2.
y());
1432 :
n(plane.
n),
p(plane.
p)
1437 double A = vec[0].y()*(vec[1].z() - vec[2].z()) +
1438 vec[1].
y()*(vec[2].z() - vec[0].z()) +
1439 vec[2].
y()*(vec[0].z() - vec[1].z());
1440 double B = vec[0].z()*(vec[1].x() - vec[2].x()) +
1441 vec[1].
z()*(vec[2].x() - vec[0].x()) +
1442 vec[2].
z()*(vec[0].x() - vec[1].x());
1443 double C = vec[0].x()*(vec[1].y() - vec[2].y()) +
1444 vec[1].
x()*(vec[2].y() - vec[0].y()) +
1445 vec[2].
x()*(vec[0].y() - vec[1].y());
1459 double A()
const {
return(
n.
x()); };
1460 double B()
const {
return(
n.
y()); };
1461 double C()
const {
return(
n.
z()); };
1464 return( -1.0 * (
n.
x()*
p.
x() +
n.
y()*
p.
y() +
n.
z()*
p.
z()));
1472 return(fabs(
n.
x()*P.
x() +
n.
y()*P.
y() +
n.
z()*P.
z() +
D()) <=
TOL);
1480 template<
typename Po
intContainer>
1486 double np = 1.0/
static_cast<double>(pc.size());
1487 typename PointContainer::const_iterator
pi = pc.begin();
1488 while(pi != pc.end()){
1500 template<
typename Po
intContainer>
1506 double np = 1.0/
static_cast<double>(pc.size());
1507 typename PointContainer::const_iterator
pi = pc.begin();
1508 while(pi != pc.end()){
1542 std::vector<CPoint>::const_iterator
pi = v.begin();
1543 while(pi != v.end())
1544 this->push_back(*pi++);
1548 std::vector<CPoint>::const_iterator fi = face.begin();
1549 while(fi != face.end())
1550 this->push_back(*fi++);
1554 CVector v1((*
this)[0],(*
this)[1]);
1555 CVector v2((*
this)[0],(*
this)[2]);
1565 std::vector<CPoint>::const_iterator fi = face.begin();
1566 while(fi != face.end())
1567 this->push_back(*fi++);
1572 std::vector<CPoint>::const_iterator li = this->begin();
1573 std::vector<CPoint>::const_iterator fi = face.begin();
1574 if(this->size() != face.size())
return false;
1575 while(li != this->end())
1576 if(!(*li++ == *fi++))
1582 CPlane plane((*
this)[0],(*
this)[1],(*
this)[2]);
1585 std::vector<CPoint>::const_iterator fi = this->begin();
1590 while(fi != this->end()){
1592 angle +=
acos(v*vp);
1596 angle +=
acos(vp*v1);
1597 return((fabs(angle) - 2*
PI) <=
TOL);
1604 class C3Facet :
public std::vector<const C3Point *>
1650 std::vector<const C3Point *>::const_iterator
pi = v.begin();
1651 while(pi != v.end())
1652 this->push_back(*pi++);
1662 C3Facet::const_iterator fi = face.begin();
1663 while(fi != face.end())
1664 this->push_back(*fi++);
1668 C3Vector v1(*((*
this)[0]),*((*
this)[1]));
1669 C3Vector v2(*((*
this)[0]),*((*
this)[2]));
1679 C3Facet::const_iterator fi = face.begin();
1680 while(fi != face.end())
1681 this->push_back(*fi++);
1686 C3Facet::const_iterator li = this->begin();
1687 C3Facet::const_iterator fi = face.begin();
1688 if(this->size() != face.size())
return false;
1689 while(li != this->end())
1690 if(!(*(*li++) == *(*fi++)))
1735 Distance(
const CPoint &p,
const CLine &l);
1738 #endif // GeoPrimitives
/brief Cartesian 3 Vector
bool operator>(const CPoint &p) const
const CPoint & min() const
CBox & operator=(const CBox &b)
C3Point * _copycreate_point(const C3Point &p)
const double & operator[](unsigned int i) const
bool operator==(const CPlane &plane) const
bool operator<=(const CPoint &p) const
C3Vector operator+(const C3Vector &v2) const
CVector & operator%=(const CVector &v2)
friend double Distance(const CPoint &p, const GeoPrim::CLine &l)
CVector operator%(const CVector &v2) const
CBox(const CPoint &ip1, const CPoint &ip2)
C3Vector & Init(const double *a)
CLineSegment(const CPoint &pb, const CPoint &pe)
const C3Point & point() const
void AddPoint(const CPoint &p)
CPoint(double ix, double iy, double iz=0.0)
void init(const double *points, unsigned int n)
friend double Distance(const CPoint &p, const CLine &l)
bool operator<(const CVector &v) const
bool operator<(const CPoint &p) const
const CVector & normal() const
C3Vector & Init(const C3Vector &v)
const CPoint & P2() const
void int int REAL REAL * y
friend std::istream & operator>>(std::istream &iSt, CPoint &p)
CVector(const CPoint &p1, const CPoint &p2)
C3Plane(const C3Vector &N, const C3Point &P)
const CPoint & point1() const
CVector(const CVector &v)
C3Vector(double ix, double iy, double iz=0.0)
C3Vector & operator+=(const C3Vector &v2)
const CPoint & point() const
bool operator>=(const C3Vector &v) const
CVector & init(const double *a)
bool operator==(const CVector &v) const
bool operator>(const CBox &b) const
C3Plane & operator=(const C3Plane &plane)
CVector & operator-=(const CVector &v2)
C3Vector operator-(const C3Vector &v2) const
C3Vector(const C3Vector &p1, const C3Vector &p2)
C3Vector & Init(const C3Vector &p1, const C3Vector &p2)
double operator*(const C3Vector &v2) const
Dot Product.
CLineSegment & point1(const CPoint &p)
CPoint & set(double ix, double iy, double iz)
bool contains(const double *p) const
CVector & init(const CPoint &p1, const CPoint &p2)
CPlane(const CVector &N, const CPoint &P)
bool contains_point(const CPoint &P) const
CVector operator*(double num) const
CVector & operator+=(const CPoint &p)
C3Facet(const C3Point &P1, const C3Point &P2, const C3Point &P3, const C3Point &P4)
C3Facet & operator=(const C3Facet &face)
bool contains(const CPoint &p) const
friend std::istream & operator>>(std::istream &, C3Vector &)
bool operator!=(const CPoint &p) const
CVector & operator*=(double num)
CVector(double ix, double iy, double iz=0.0)
bool operator<=(const CVector &v) const
CFacet(const CPoint &P1, const CPoint &P2, const CPoint &P3, const CPoint &P4)
CPoint & operator*=(double num)
C3Point C3Centroid(const PointContainer &pc)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
CBox(const std::vector< CPoint > &pv)
C3Vector & operator-=(const C3Vector &v2)
double & operator[](unsigned int i)
CPoint operator*(double num) const
CVector operator+(const CVector &v2) const
CFacet(const std::vector< CPoint > &v)
const CPoint & point2() const
CLine(const CPoint &p1, const CPoint &p2)
C3Vector(const C3Vector &v)
C3Vector & Copy(const C3Vector &v)
C3Vector(const GeoPrim::CVector &inv)
CVector & init(const CVector &v)
bool operator==(const C3Plane &plane) const
CPoint & operator-=(const CPoint &p)
C3Point * _create_point()
void int int int REAL REAL REAL * z
CPoint operator-(const CPoint &p) const
CVector & init(double ix, double iy, double iz)
bool operator==(const CLine &l) const
bool operator==(const CPoint &p) const
double & operator[](unsigned int i)
CVector & init(const CPoint &p)
friend std::ostream & operator<<(std::ostream &, const C3Vector &)
CVector & operator=(const CVector &v2)
const CVector & slope() const
const double & operator[](unsigned int i) const
CVector & operator+=(const CVector &v2)
C3Vector operator%(const C3Vector &v2) const
Cross Product.
double angle(Vector_3< double > v1, Vector_3< double > v2)
Compute the angle between two vectors.
CBox(const double *points, unsigned int n)
CPoint Centroid(const PointContainer &pc)
const CPoint & point() const
C3Vector operator*(double num) const
Scaling.
CLineSegment & point2(const CPoint &p)
bool contains_point(const CPoint &P)
double operator*(const CVector &v2) const
CFacet(const CFacet &face)
CImg< _cimg_Tfloat > atan(const CImg< T > &instance)
C3Vector & Init(double ix, double iy, double iz)
const C3Vector & normal() const
bool operator==(const C3Facet &face) const
CLine(const CPoint &p1, const CVector &v1)
friend std::istream & operator>>(std::istream &, CVector &)
friend CVector operator*(double, const CVector &)
CFacet & operator=(const CFacet &face)
bool operator<(const CBox &b) const
C3Plane(const std::vector< C3Point > &vec)
CPoint & init(const double *p)
bool operator>=(const CPoint &p) const
void Transpose(CVector matrix[])
CPoint & copy(const CPoint &p)
friend CPoint operator*(double, const CPoint &p)
C3Vector & operator%=(const C3Vector &v2)
C3Facet(const C3Point &P1, const C3Point &P2, const C3Point &P3)
friend C3Vector operator*(double, const C3Vector &)
C3Facet(const C3Point *P1, const C3Point *P2, const C3Point *P3)
CVector & copy(const CVector &v2)
CVector & operator=(const CPoint &p)
CPoint & init(double ix, double iy, double iz=0.0)
bool operator==(const CBox &b) const
C3Vector(const CPoint &inp)
CPoint & operator=(const CPoint &p)
CPlane(const std::vector< CPoint > &vec)
CBox around(const CPoint &p) const
CPoint & operator+=(const CPoint &p)
CFacet(const CPoint &P1, const CPoint &P2, const CPoint &P3)
bool has_point(const CPoint &p2) const
CVector operator-(const CVector &v2) const
friend std::ostream & operator<<(std::ostream &, const CBox &)
bool has_point(const CPoint &p3) const
void inv(Matrix3D &Ainv, const Matrix3D &A)
bool operator<(const C3Vector &v) const
CPlane & operator=(const CPlane &plane)
bool operator>(const CVector &v) const
bool operator>(const C3Vector &v) const
C3Facet(const C3Point *P1, const C3Point *P2, const C3Point *P3, const C3Point *P4)
bool contains_point(const C3Point &P) const
bool operator>=(const CVector &v) const
void merge(const CBox &b)
CBox intersect(const CBox &b) const
C3Plane(const C3Point &p1, const C3Point &p2, const C3Point &p3)
CPoint operator+(const CPoint &p) const
friend std::ostream & operator<<(std::ostream &oSt, const CPoint &p)
CImg< _cimg_Tfloat > acos(const CImg< T > &instance)
CPlane(const CPlane &plane)
C3Vector(const double *a)
bool collide(const CBox &b) const
double & operator[](unsigned int i)
friend std::ostream & operator<<(std::ostream &, const CVector &)
C3Vector & operator*=(double num)
C3Facet(const C3Facet &face)
double Distance(const CPoint &p) const
C3Facet(const std::vector< const C3Point * > &v)
CLineSegment(const CPoint &p)
bool operator==(const C3Vector &v) const
CLine & move(const CPoint &p1)
double Distance(const CPoint &p, const CLine &l)
C3Vector & operator=(const C3Vector &v2)
void Transpose_2x3(CVector matrix[], double tpose[][2])
const CPoint & max() const
C3Plane(const C3Plane &plane)
const double & operator[](unsigned int i) const
const CPoint & P1() const
CPlane(const CPoint &p1, const CPoint &p2, const CPoint &p3)
bool operator==(const CFacet &face) const
bool operator<=(const C3Vector &v) const