Geom Software - C++ Programming and Geometry Libraries
FADEPLACEHOLDER Documentation pages v1.03
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 
40 Point3(const double x_,const double y_,const double z_):
41  coordX(x_),
42  coordY(y_),
43  coordZ(z_)
44 {
45 }
46 
47 
52 Point3():coordX(0),coordY(0),coordZ(0)
53 {
54 }
55 
56 
60 Point3(const Point3& p_):
61  coordX(p_.x()),
62  coordY(p_.y()),
63  coordZ(p_.z())
64 {
65 }
66 
69 Point3 &operator=(const Point3& other)
70 {
71  coordX=other.x();
72  coordY=other.y();
73  coordZ=other.z();
74  return *this;
75 }
76 
80 {
81 }
82 
87 double x() const
88 {
89  return coordX;
90 }
91 
92 
97 double y() const
98 {
99  return coordY;
100 }
101 
102 
107 double z() const
108 {
109  return coordZ;
110 }
111 
112 
120 void xyz(double& x_,double& y_,double& z_) const
121 {
122  x_=coordX;
123  y_=coordY;
124  z_=coordZ;
125 }
126 
127 
128 
133 inline void addSelf(double& x,double& y,double& z) const
134 {
135  x+=coordX;
136  y+=coordY;
137  z+=coordZ;
138 }
139 
146  bool operator<(const Point3& p) const
147  {
148  if(coordX<p.coordX) return true;
149  if(coordX>p.coordX) return false;
150  if(coordY<p.coordY) return true;
151  if(coordY>p.coordY) return false;
152  return coordZ<p.coordZ;
153  }
154 
161  bool operator>(const Point3& p) const
162  {
163  if(coordX>p.coordX) return true;
164  if(coordX<p.coordX) return false;
165  if(coordY>p.coordY) return true;
166  if(coordY<p.coordY) return false;
167  return coordY>p.coordY;
168  }
173  bool operator==(const Point3& p) const
174  {
175  if(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ) return true;
176  return false;
177  }
182 bool operator!=(const Point3& p) const
183 {
184  return (coordX!=p.coordX || coordY!=p.coordY || coordZ!=p.coordZ);
185 }
186 
187 
192 void set(const double x_,const double y_,const double z_)
193 {
194  coordX=x_;
195  coordY=y_;
196  coordZ=z_;
197 }
198 
203 void set(const Point3& pnt)
204 {
205  coordX=pnt.x();
206  coordY=pnt.y();
207  coordZ=pnt.z();
208 }
209 
210 
211 
212 
217 Vector3 operator-(const Point3& other) const
218 {
219  double xdiff(x()-other.x());
220  double ydiff(y()-other.y());
221  double zdiff(z()-other.z());
222  return Vector3(xdiff,ydiff,zdiff);
223 }
224 
229 Point3 operator+(const Vector3& vec) const
230 {
231  return Point3(x()+vec.x(),y()+vec.y(),z()+vec.z());
232 }
233 
234 
239 Point3 operator-(const Vector3& vec) const
240 {
241  return Point3(x()-vec.x(),y()-vec.y(),z()-vec.z());
242 }
243 
244 
245 friend std::ostream &operator<<(std::ostream &stream, const Point3& pnt);
246 friend std::istream &operator>>(std::istream &stream, Point3& pnt);
247 
248 
249 protected:
250 friend class Dt2;
251  double coordX;
252  double coordY;
253  double coordZ;
254 };
255 
256 
257 inline std::ostream &operator<<(std::ostream &stream, const Point3& pnt)
258 {
259  stream << "Point3 ("<<&pnt<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
260  return stream;
261 }
262 
263 inline std::istream &operator>>(std::istream &stream, Point3& pnt)
264 {
265  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
266  return stream;
267 }
268 
269 
272 inline double sqDistance(const Point3& p0,const Point3& p1)
273 {
274  double deltaX=p1.x()-p0.x();
275  double deltaY=p1.y()-p0.y();
276  double deltaZ=p1.z()-p0.z();
277  return (deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
278 }
279 
280 
283 inline double distance(const Point3& p0,const Point3& p1)
284 {
285  double deltaX=p1.x()-p0.x();
286  double deltaY=p1.y()-p0.y();
287  double deltaZ=p1.z()-p0.z();
288  return sqrt(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
289 }
290 
291 
294 inline
295 Point3 center(const Point3& p0,const Point3& p1)
296 {
297  Point3 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
298  return center;
299 }
300 
301 
302 } // (namespace)
Point3(const double x_, const double y_, const double z_)
Constructor.
Definition: Point3.h:40
Point3(const Point3 &p_)
Copy constructor.
Definition: Point3.h:60
void addSelf(double &x, double &y, double &z) const
Add the point&#39;s coordinates to x,y,z.
Definition: Point3.h:133
double z() const
Get the z-coordinate.
Definition: Point3.h:107
bool operator==(const Point3 &p) const
Equality operator.
Definition: Point3.h:173
double y() const
Get the y-coordinate.
Definition: Point3.h:97
double x() const
Get the x-coordinate.
Definition: Point3.h:87
~Point3()
Destructor.
Definition: Point3.h:79
3D Point
Definition: Point3.h:30
Point3 operator-(const Vector3 &vec) const
operator-
Definition: Point3.h:239
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:120
Definition: Point3.h:23
bool operator!=(const Point3 &p) const
Inequality operator.
Definition: Point3.h:182
bool operator>(const Point3 &p) const
Greater than operator.
Definition: Point3.h:161
3D Vector
Definition: Vector3.h:26
Point3 operator+(const Vector3 &vec) const
operator+
Definition: Point3.h:229
Point3()
Default constructor.
Definition: Point3.h:52
bool operator<(const Point3 &p) const
Less than operator.
Definition: Point3.h:146
Point3 & operator=(const Point3 &other)
operator=
Definition: Point3.h:69
Vector3 operator-(const Point3 &other) const
operator-
Definition: Point3.h:217
double y() const
Get the y-value.