Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.04
Point3.h
1 // Copyright (C) Geom Software e.U, Bernhard Kornberger, Graz/Austria
2 //
3 // This file is part of the WOF software. WOF is commercial software.
4 // Users holding a license may use this file in accordance with the
5 // License Agreement.
6 //
7 // This software is provided AS IS with NO WARRANTY OF ANY KIND,
8 // INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
9 // FOR A PARTICULAR PURPOSE.
10 //
11 // Please contact the author if any conditions of this licensing are
12 // not clear to you.
13 //
14 // Author: Bernhard Kornberger, bkorn (at) geom.at
15 // http://www.geom.at
16 
17 
18 #pragma once
19 
20 #include <math.h>
21 #include "Vector3.h"
22 
23 namespace GEOM_WOF {
24 
25 
26 class Triangle2; // FWD
27 
30 class CLASS_DECLSPEC Point3
31 {
32 public:
33 
38 Point3(const double x_,const double y_,const double z_):
39  coordX(x_),
40  coordY(y_),
41  coordZ(z_)
42 {
43 }
44 
45 
50 Point3():coordX(0),coordY(0),coordZ(0)
51 {
52 }
53 
54 
59 Point3(const Point3& p_):
60  coordX(p_.x()),
61  coordY(p_.y()),
62  coordZ(p_.z())
63 {
64 }
65 
70 Point3 &operator=(const Point3& other)
71 {
72  coordX=other.x();
73  coordY=other.y();
74  coordZ=other.z();
75  return *this;
76 }
77 
81 {
82 }
83 
88 double x() const
89 {
90  return coordX;
91 }
92 
93 
98 double y() const
99 {
100  return coordY;
101 }
102 
103 
108 double z() const
109 {
110  return coordZ;
111 }
112 
113 
121 void xyz(double& x_,double& y_,double& z_) const
122 {
123  x_=coordX;
124  y_=coordY;
125  z_=coordZ;
126 }
127 
128 
129 
134 inline void addOwnCoords(double& x,double& y,double& z) const
135 {
136  x+=coordX;
137  y+=coordY;
138  z+=coordZ;
139 }
140 
147  bool operator<(const Point3& p) const
148  {
149  if(coordX<p.coordX) return true;
150  if(coordX>p.coordX) return false;
151  if(coordY<p.coordY) return true;
152  if(coordY>p.coordY) return false;
153  return coordZ<p.coordZ;
154  }
155 
163  bool operator>(const Point3& p) const
164  {
165  if(coordX>p.coordX) return true;
166  if(coordX<p.coordX) return false;
167  if(coordY>p.coordY) return true;
168  if(coordY<p.coordY) return false;
169  return coordY>p.coordY;
170  }
175  bool operator==(const Point3& p) const
176  {
177  if(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ) return true;
178  return false;
179  }
184 bool operator!=(const Point3& p) const
185 {
186  return (coordX!=p.coordX || coordY!=p.coordY || coordZ!=p.coordZ);
187 }
188 
189 
196 void set(const double x_,const double y_,const double z_)
197 {
198  coordX=x_;
199  coordY=y_;
200  coordZ=z_;
201 }
202 
209 void set(const Point3& pnt)
210 {
211  coordX=pnt.x();
212  coordY=pnt.y();
213  coordZ=pnt.z();
214 }
215 
216 
217 
218 
224 Vector3 operator-(const Point3& other) const
225 {
226  double xdiff(x()-other.x());
227  double ydiff(y()-other.y());
228  double zdiff(z()-other.z());
229  return Vector3(xdiff,ydiff,zdiff);
230 }
231 
236 Point3 operator+(const Vector3& vec) const
237 {
238  return Point3(x()+vec.x(),y()+vec.y(),z()+vec.z());
239 }
240 
241 
246 Point3 operator-(const Vector3& vec) const
247 {
248  return Point3(x()-vec.x(),y()-vec.y(),z()-vec.z());
249 }
250 
251 
252 friend std::ostream &operator<<(std::ostream &stream, const Point3& pnt);
253 friend std::istream &operator>>(std::istream &stream, Point3& pnt);
254 
255 
256 protected:
257 friend class Dt2;
258  double coordX;
259  double coordY;
260  double coordZ;
261 };
262 
263 
264 inline std::ostream &operator<<(std::ostream &stream, const Point3& pnt)
265 {
266  stream << "Point3 ("<<&pnt<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
267  return stream;
268 }
269 
270 inline std::istream &operator>>(std::istream &stream, Point3& pnt)
271 {
272  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
273  return stream;
274 }
275 
276 
279 inline double sqDistance(const Point3& p0,const Point3& p1)
280 {
281  double deltaX=p1.x()-p0.x();
282  double deltaY=p1.y()-p0.y();
283  double deltaZ=p1.z()-p0.z();
284  return (deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
285 }
286 
287 
290 inline double distance(const Point3& p0,const Point3& p1)
291 {
292  double deltaX=p1.x()-p0.x();
293  double deltaY=p1.y()-p0.y();
294  double deltaZ=p1.z()-p0.z();
295  return sqrt(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
296 }
297 
298 
301 inline
302 Point3 center(const Point3& p0,const Point3& p1)
303 {
304  Point3 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
305  return center;
306 }
307 
308 
309 } // (namespace)
Point3(const double x_, const double y_, const double z_)
Constructor.
Definition: Point3.h:38
Point3(const Point3 &p_)
Copy constructor.
Definition: Point3.h:59
Point3 center(const Point3 &p0, const Point3 &p1)
Midpoint of p0 and p1.
Definition: Point3.h:302
double z() const
Get the z-coordinate.
Definition: Point3.h:108
bool operator==(const Point3 &p) const
Equality operator.
Definition: Point3.h:175
double y() const
Get the y-coordinate.
Definition: Point3.h:98
double x() const
Get the x-coordinate.
Definition: Point3.h:88
double distance(const Point3 &p0, const Point3 &p1)
Get the squared distance between two points.
Definition: Point3.h:290
double sqDistance(const Point3 &p0, const Point3 &p1)
Get the squared distance between two points.
Definition: Point3.h:279
~Point3()
Destructor.
Definition: Point3.h:80
3D Point
Definition: Point3.h:30
void addOwnCoords(double &x, double &y, double &z) const
Add the point&#39;s coordinates to x,y,z.
Definition: Point3.h:134
Point3 operator-(const Vector3 &vec) const
operator-
Definition: Point3.h:246
double z() const
Get the z-value.
double x() const
Get the x-value.
void xyz(double &x_, double &y_, double &z_) const
Get the x-, y- and z-coordinate.
Definition: Point3.h:121
Definition: Point3.h:23
bool operator!=(const Point3 &p) const
Inequality operator.
Definition: Point3.h:184
bool operator>(const Point3 &p) const
Greater than operator.
Definition: Point3.h:163
3D Vector
Definition: Vector3.h:26
Point3 operator+(const Vector3 &vec) const
operator+
Definition: Point3.h:236
Point3()
Default constructor.
Definition: Point3.h:50
bool operator<(const Point3 &p) const
Less than operator.
Definition: Point3.h:147
Point3 & operator=(const Point3 &other)
operator=
Definition: Point3.h:70
Vector3 operator-(const Point3 &other) const
operator-
Definition: Point3.h:224
double y() const
Get the y-value.