Point3D.hpp
Go to the documentation of this file.
1 //
2 // Point3D.hpp
3 // A 3-dimensional cartesian point.
4 //
5 
6 
7 #ifndef POINT3D_HPP
8 #define POINT3D_HPP
9 
10 #include <cassert>
11 #include <sstream>
12 #include <iosfwd> // for istream, ostream
13 #include <utility> // for std::pair<T,T>
14 #include "../BasicDatatypes.hpp"
15 #include "../tools/MathToolbox.hpp" // for fuzzyCompare
16 
17 namespace datatypes
18 {
19 
20 class Point2D;
21 
22 
25 class Point3D : public BasicData
26 {
27 public:
29  typedef double floatingpoint_type;
30 
31 private:
32  double m_x;
33  double m_y;
34  double m_z;
35 
36 public:
38  Point3D(double x, double y, double z)
39  : m_x(x)
40  , m_y(y)
41  , m_z(z)
43 
46  : m_x(0.0)
47  , m_y(0.0)
48  , m_z(0.0)
50 
52  explicit Point3D(const Point2D& p);
53 
54  // Estimate the memory usage of this object
55  inline virtual const UINT32 getUsedMemory() const {return sizeof(*this);};
56 
57 
58 
60  //\{
61 
62  bool isZero() const;
63  double getX() const { return m_x; }
64  double getY() const { return m_y; }
65  double getZ() const { return m_z; }
66 
67  double length() const;
68  double distFromOrigin() const;
69 
70  double getAngleAroundX() const;
71  double getAngleAroundY() const;
72  double getAngleAroundZ() const;
73 
75  Point2D toPoint2D() const;
76  //\}
77 
79  //\{
80 
81  void setX(double x) { m_x = x; }
82  void setY(double y) { m_y = y; }
83  void setZ(double z) { m_z = z; }
84  void setXYZ(double x, double y, double z) { m_x = x; m_y = y; m_z = z; }
85 
86  void rotateAroundX(double rollAngle);
87  void rotateAroundY(double pitchAngle);
88  void rotateAroundZ(double dYawAngle);
89 
90  void normalize();
91 
92  Point3D & operator+= ( const Point3D & point );
93  Point3D & operator-= ( const Point3D & point );
94  Point3D & operator/= ( double divisor );
95  //\}
96 
97 
99  //\{
100  double dist( const Point3D& point ) const;
101  //\}
102 
103 
105  //\{
106  static Point3D vectorProduct(const Point3D& v1, const Point3D& v2);
107  static Point3D calcIntersectionPointOfVectorWithPlane(const Point3D& PlaneStartpoint,
108  const Point3D& PlaneNormal,
109  const Point3D& VectorStartpoint,
110  const Point3D& VectorDirection);
111  static double getDistanceBetweenPoints(const Point3D& pt1, const Point3D& pt2);
112  //\}
113 
114 
116  //\{
117 
119 
122  std::istream& read (std::istream& is); // , UINT32 version); ///< Reads a Point3D from an input stream
123  void read (const BYTE*& buf); // , UINT32 version); ///< Reads a Point3D from a memory buffer and increments the buffer pointer
124  std::ostream& write (std::ostream& os) const; // , UINT32 version) const; ///< Writes a Point3D to an output stream
125  void write (BYTE*& buf) const; //, UINT32 version) const; ///< Writes a Point2D to a memory buffer and increments the buffer pointer
126  std::string toString() const;
127 
128  //\}
129 
130  static std::streamsize getSerializedSize(); // UINT32 version); ///< Returns the number of bytes this object needs in serialized form
131 
132  friend inline bool operator==(const Point3D &, const Point3D &);
133  friend inline bool operator!=(const Point3D &, const Point3D &);
134  friend inline const Point3D operator+(const Point3D &, const Point3D &);
135  friend inline const Point3D operator-(const Point3D &, const Point3D &);
136  friend inline double operator*(const Point3D &, const Point3D &);
137  friend inline const Point3D operator*(double, const Point3D &);
138  friend inline const Point3D operator*(const Point3D &, double);
139  friend inline const Point3D operator-(const Point3D &);
140  friend inline const Point3D operator/(const Point3D &, double);
141 };
142 
143 std::ostream& operator<<(std::ostream& os, const Point3D& point);
144 
145 // Inline functions
146 
147 inline Point3D & Point3D::operator+= ( const Point3D & point )
148 {
149  m_x += point.m_x;
150  m_y += point.m_y;
151  m_z += point.m_z;
152  return *this;
153 }
154 
155 inline Point3D & Point3D::operator-= ( const Point3D & point )
156 {
157  m_x -= point.m_x;
158  m_y -= point.m_y;
159  m_z -= point.m_z;
160  return *this;
161 }
162 
163 inline Point3D & Point3D::operator/= ( double divisor )
164 {
165  assert(!fuzzyCompare(divisor, 0.0));
166  m_x /= divisor;
167  m_y /= divisor;
168  m_z /= divisor;
169 
170  return *this;
171 }
172 
173 inline bool operator==(const Point3D &p1, const Point3D &p2)
174 {
175  return (fuzzyCompare(p1.m_x, p2.m_x)
176  || (isNaN(p1.m_x) && isNaN(p2.m_x)))
177  && (fuzzyCompare(p1.m_y, p2.m_y)
178  || (isNaN(p1.m_y) && isNaN(p2.m_y)))
179  && (fuzzyCompare(p1.m_z, p2.m_z)
180  || (isNaN(p1.m_z) && isNaN(p2.m_z)));
181 }
182 inline bool operator!=(const Point3D &p1, const Point3D &p2)
183 {
184  return ! operator==(p1, p2);
185 }
186 
187 inline const Point3D operator+(const Point3D &p1, const Point3D &p2)
188 {
189  return Point3D(p1.m_x + p2.m_x, p1.m_y + p2.m_y, p1.m_z + p2.m_z);
190 }
191 
192 
193 inline const Point3D operator-(const Point3D &p1, const Point3D &p2)
194 {
195  return Point3D(p1.m_x - p2.m_x, p1.m_y - p2.m_y, p1.m_z - p2.m_z);
196 }
197 
198 // wert = v1 * v2
199 inline double operator*(const Point3D &p1, const Point3D &p2)
200 {
201  return ((p1.m_x * p2.m_x) + (p1.m_y * p2.m_y) + (p1.m_z * p2.m_z));
202 }
203 
204 
205 inline const Point3D operator*(const Point3D &p, double factor)
206 {
207  return Point3D(p.m_x * factor, p.m_y * factor, p.m_z * factor);
208 }
209 
210 inline const Point3D operator*(double factor, const Point3D &p)
211 {
212  return Point3D(p.m_x * factor, p.m_y * factor, p.m_z * factor);
213 }
214 
215 
216 inline const Point3D operator-(const Point3D &p)
217 {
218  return Point3D(-p.m_x, -p.m_y, -p.m_z);
219 }
220 
221 inline const Point3D operator/(const Point3D &p, double divisor)
222 {
223  assert(fuzzyCompare(divisor, 0.0) == false);
224  return Point3D(p.m_x / divisor, p.m_y / divisor, p.m_z / divisor);
225 }
226 
227 // ////////////////////////////////////////////////////////////
228 
229 } // namespace datatypes
230 
231 
232 #endif
233 
void setXYZ(double x, double y, double z)
Sets the coordinates of this point to the given values.
Definition: Point3D.hpp:84
unsigned char BYTE
This class defines a point in the three-dimensional plane.
Definition: Point3D.hpp:25
double getY() const
Returns the y-coordinate of this point.
Definition: Point3D.hpp:64
std::string toString() const
Text output for debugging.
Definition: Point3D.cpp:262
static Point3D calcIntersectionPointOfVectorWithPlane(const Point3D &PlaneStartpoint, const Point3D &PlaneNormal, const Point3D &VectorStartpoint, const Point3D &VectorDirection)
Definition: Point3D.cpp:293
void setX(double x)
Sets the x-coordinate of this point to the given value.
Definition: Point3D.hpp:81
double getAngleAroundZ() const
Returns the rotation angle around z (in the x-y-plane)
Definition: Point3D.cpp:179
void normalize()
Normalizes this vector (point) to length 1.0.
Definition: Point3D.cpp:74
Point2D toPoint2D() const
Returns the x/y components of this class, converted into a Point2D object.
Definition: Point3D.cpp:48
double dist(const Point3D &point) const
Calculates the distance to the given point.
Definition: Point3D.cpp:43
void rotateAroundZ(double dYawAngle)
Rotate the point around the Z-axis ("Yaw angle")
Definition: Point3D.cpp:96
double floatingpoint_type
The type of the stored x and y coordinates.
Definition: Point3D.hpp:29
uint32_t UINT32
friend const Point3D operator-(const Point3D &, const Point3D &)
Definition: Point3D.hpp:193
friend double operator*(const Point3D &, const Point3D &)
Definition: Point3D.hpp:199
virtual const UINT32 getUsedMemory() const
Definition: Point3D.hpp:55
Point3D & operator+=(const Point3D &point)
Adds the given point to this point and returns a reference to this point.
Definition: Point3D.hpp:147
friend const Point3D operator/(const Point3D &, double)
Definition: Point3D.hpp:221
double distFromOrigin() const
Dist from the point (0,0,0) to this point.
Definition: Point3D.cpp:146
bool isZero() const
Check against (near-)zero.
Definition: Point3D.cpp:35
void setY(double y)
Sets the y-coordinate of this point to the given value.
Definition: Point3D.hpp:82
static Point3D vectorProduct(const Point3D &v1, const Point3D &v2)
Returns the vector product ("Kreuzprodukt") of the two vectors.
Definition: Point3D.cpp:58
double getZ() const
Returns the z-coordinate of this point.
Definition: Point3D.hpp:65
friend const Point3D operator+(const Point3D &, const Point3D &)
Definition: Point3D.hpp:187
double length() const
Length of the vector (identical to distFromOrigin())
Definition: Point3D.cpp:155
double getAngleAroundY() const
Returns the rotation angle around y (in the z-x-plane)
Definition: Point3D.cpp:207
double getX() const
Returns the x-coordinate of this point.
Definition: Point3D.hpp:63
friend bool operator!=(const Point3D &, const Point3D &)
Definition: Point3D.hpp:182
bool fuzzyCompare(double a, double b)
Tests if two double values are nearly equal.
Definition: MathToolbox.hpp:28
void rotateAroundX(double rollAngle)
Rotate the point around the X-axis ("Roll angle")
Definition: Point3D.cpp:113
static std::streamsize getSerializedSize()
double getAngleAroundX() const
Returns the rotation angle around x (in the z-y-plane)
Definition: Point3D.cpp:235
static double getDistanceBetweenPoints(const Point3D &pt1, const Point3D &pt2)
Returns the distance between the two point coordinates.
Definition: Point3D.cpp:250
Point3D & operator/=(double divisor)
Definition: Point3D.hpp:163
Point3D & operator-=(const Point3D &point)
Subtracts the given point to this point and returns a reference to this point.
Definition: Point3D.hpp:155
bool isNaN(floatT x)
Checks if a floating point value is Not-a-Number (NaN)
Definition: MathToolbox.hpp:63
void setZ(double z)
Sets the z-coordinate of this point to the given value.
Definition: Point3D.hpp:83
std::ostream & write(std::ostream &os) const
std::istream & read(std::istream &is)
Reads a Point3D from an input stream.
std::ostream & operator<<(std::ostream &os, const EvalCaseResult &result)
Point3D(double x, double y, double z)
Definition: Point3D.hpp:38
friend bool operator==(const Point3D &, const Point3D &)
Definition: Point3D.hpp:173
void rotateAroundY(double pitchAngle)
Rotate the point around the Y-axis ("Pitch angle")
Definition: Point3D.cpp:129


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Mon Oct 26 2020 03:27:30