Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.12
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 
146 inline void addWeightedOwnCoords(double weight,double& x,double& y,double& z) const
147 {
148  x+=(weight*coordX);
149  y+=(weight*coordY);
150  z+=(weight*coordZ);
151 }
152 
159  bool operator<(const Point3& p) const
160  {
161  if(coordX<p.coordX) return true;
162  if(coordX>p.coordX) return false;
163  if(coordY<p.coordY) return true;
164  if(coordY>p.coordY) return false;
165  return coordZ<p.coordZ;
166  }
167 
175  bool operator>(const Point3& p) const
176  {
177  if(coordX>p.coordX) return true;
178  if(coordX<p.coordX) return false;
179  if(coordY>p.coordY) return true;
180  if(coordY<p.coordY) return false;
181  return coordY>p.coordY;
182  }
187  bool operator==(const Point3& p) const
188  {
189  if(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ) return true;
190  return false;
191  }
196 bool operator!=(const Point3& p) const
197 {
198  return (coordX!=p.coordX || coordY!=p.coordY || coordZ!=p.coordZ);
199 }
200 
201 
208 void set(const double x_,const double y_,const double z_)
209 {
210  coordX=x_;
211  coordY=y_;
212  coordZ=z_;
213 }
214 
221 void set(const Point3& pnt)
222 {
223  coordX=pnt.x();
224  coordY=pnt.y();
225  coordZ=pnt.z();
226 }
227 
228 
229 
230 
236 Vector3 operator-(const Point3& other) const
237 {
238  double xdiff(x()-other.x());
239  double ydiff(y()-other.y());
240  double zdiff(z()-other.z());
241  return Vector3(xdiff,ydiff,zdiff);
242 }
243 
248 Point3 operator+(const Vector3& vec) const
249 {
250  return Point3(x()+vec.x(),y()+vec.y(),z()+vec.z());
251 }
252 
253 
258 Point3 operator-(const Vector3& vec) const
259 {
260  return Point3(x()-vec.x(),y()-vec.y(),z()-vec.z());
261 }
262 
263 
264 friend std::ostream &operator<<(std::ostream &stream, const Point3& pnt);
265 friend std::istream &operator>>(std::istream &stream, Point3& pnt);
266 
267 
268 protected:
269  double coordX;
270  double coordY;
271  double coordZ;
272 };
273 
274 
275 
276 
277 
278 
279 
280 
281 // Free functions
282 inline std::ostream &operator<<(std::ostream &stream, const Point3& pnt)
283 {
284  stream << "Point3 ("<<&pnt<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
285  return stream;
286 }
287 
288 inline std::istream &operator>>(std::istream &stream, Point3& pnt)
289 {
290  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
291  return stream;
292 }
293 
294 
297 inline double sqDistance(const Point3& p0,const Point3& p1)
298 {
299  double deltaX=p1.x()-p0.x();
300  double deltaY=p1.y()-p0.y();
301  double deltaZ=p1.z()-p0.z();
302  return (deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
303 }
304 
307 inline double sqDistance(const Point3* p0,const Point3* p1)
308 {
309  double deltaX=p1->x()-p0->x();
310  double deltaY=p1->y()-p0->y();
311  double deltaZ=p1->z()-p0->z();
312  return (deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
313 }
314 
315 
318 inline double distance(const Point3& p0,const Point3& p1)
319 {
320  double deltaX=p1.x()-p0.x();
321  double deltaY=p1.y()-p0.y();
322  double deltaZ=p1.z()-p0.z();
323  return sqrt(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
324 }
325 
326 
329 inline
330 Point3 center(const Point3& p0,const Point3& p1)
331 {
332  Point3 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
333  return center;
334 }
335 
336 
337 } // (namespace)
3D Point
Definition: Point3.h:31
bool operator<(const Point3 &p) const
Less than operator.
Definition: Point3.h:159
double x() const
Get the x-coordinate.
Definition: Point3.h:88
Point3 & operator=(const Point3 &other)
operator=
Definition: Point3.h:70
Point3 operator-(const Vector3 &vec) const
operator-
Definition: Point3.h:258
double y() const
Get the y-coordinate.
Definition: Point3.h:98
Point3()
Default constructor.
Definition: Point3.h:50
Vector3 operator-(const Point3 &other) const
operator-
Definition: Point3.h:236
void set(const double x_, const double y_, const double z_)
Set the coordiantes.
Definition: Point3.h:208
bool operator!=(const Point3 &p) const
Inequality operator.
Definition: Point3.h:196
Point3 operator+(const Vector3 &vec) const
operator+
Definition: Point3.h:248
void addOwnCoords(double &x, double &y, double &z) const
Add the point's coordinates to x,y,z.
Definition: Point3.h:134
~Point3()
Destructor.
Definition: Point3.h:80
void xyz(double &x_, double &y_, double &z_) const
Get the x-, y- and z-coordinate.
Definition: Point3.h:121
void set(const Point3 &pnt)
Set the coordiantes.
Definition: Point3.h:221
bool operator>(const Point3 &p) const
Greater than operator.
Definition: Point3.h:175
bool operator==(const Point3 &p) const
Equality operator.
Definition: Point3.h:187
double z() const
Get the z-coordinate.
Definition: Point3.h:108
void addWeightedOwnCoords(double weight, double &x, double &y, double &z) const
Add the point's weighted coordinates to x,y,z.
Definition: Point3.h:146
Point3(const Point3 &p_)
Copy constructor.
Definition: Point3.h:59
Point3(const double x_, const double y_, const double z_)
Constructor.
Definition: Point3.h:38
3D Vector
Definition: Vector3.h:27
double z() const
Get the z-value.
Definition: Vector3.h:88
double x() const
Get the x-value.
Definition: Vector3.h:69
double y() const
Get the y-value.
Definition: Vector3.h:78
Definition: Point3.h:23
double sqDistance(const Point3 &p0, const Point3 &p1)
Get the squared distance between two points.
Definition: Point3.h:297
Point3 center(const Point3 &p0, const Point3 &p1)
Midpoint of p0 and p1.
Definition: Point3.h:330
double distance(const Point3 &p0, const Point3 &p1)
Get the squared distance between two points.
Definition: Point3.h:318