Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.17
Vector3.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 #pragma once
18 #include <iostream>
19 #include "wof_api_definitions.h" // for CLASS_DECLSPEC
20 
21 namespace GEOM_WOF {
22 
23 
26 class CLASS_DECLSPEC Vector3
27 {
28 public:
29 
34 Vector3(const double x_,const double y_,const double z_);
35 
41 
46 Vector3(const Vector3& v_);
47 
52 bool isDegenerate() const
53 {
54  return (valX==0 && valY==0 && valZ==0);
55 }
56 
61 void xyz(double& x_,double& y_,double& z_) const
62 {
63  x_=valX;
64  y_=valY;
65  z_=valZ;
66 }
71 void reset()
72 {
73  valX=0;
74  valY=0;
75  valZ=0;
76 }
81 inline double x() const
82 {
83  return valX;
84 }
85 
86 
90 inline double y() const
91 {
92  return valY;
93 }
94 
95 
96 
100 inline double z() const
101 {
102  return valZ;
103 }
104 
111 void set(const double x_,const double y_,const double z_);
112 
117 void add(const Vector3& other)
118 {
119  valX+=other.valX;
120  valY+=other.valY;
121  valZ+=other.valZ;
122 }
123 void sub(const Vector3& other)
124 {
125  valX-=other.valX;
126  valY-=other.valY;
127  valZ-=other.valZ;
128 }
129 void div(double div)
130 {
131  valX/=div;
132  valY/=div;
133  valZ/=div;
134 }
135 void mul(double mul)
136 {
137  valX*=mul;
138  valY*=mul;
139  valZ*=mul;
140 }
141 
146 double sqLength() const;
147 
148 
149 
154 int getMaxAbsIndex() const;
155 
156 
161 double getMaxComponent() const
162 {
163  if(valX>=valY && valX>=valZ) return valX;
164  if(valY>=valZ) return valY;
165  else return valZ;
166 }
171 double getMaxAbsComponent() const;
172 
173 
179 double getCartesian(int i) const;
180 
182 bool isNV() const;
183 
188 double length() const;
189 
194 double operator*(const Vector3& other) const;
195 
196 
197 
198 
203 Vector3 operator*(double val) const;
204 
209 Vector3 operator/(double val) const;
210 
213 Vector3& operator=(const Vector3& other)
214 {
215  valX=other.valX;
216  valY=other.valY;
217  valZ=other.valZ;
218  return *this;
219 }
220 
222 void addOwnCoords(double& x,double& y,double& z) const
223 {
224  x+=valX;
225  y+=valY;
226  z+=valZ;
227 }
228 
229 Vector3& operator+=(const Vector3& other);
230 Vector3& operator-=(const Vector3& other);
231 Vector3& operator/=(double div);
232 Vector3& operator*=(double mul);
233 
234 
235 
236 protected:
237 
238 double valX;
239 double valY;
240 double valZ;
241 };
242 
243 
244 
245 
246 // Free functions
247 inline std::ostream &operator<<(std::ostream &stream, const Vector3& vec)
248 {
249  stream << "Vector3: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
250  return stream;
251 }
252 
253 
256 inline Vector3 crossProduct(const Vector3& vec0,const Vector3& vec1)
257 {
258 
259  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
260  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
261  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
262  return Vector3(x,y,z);
263 }
264 
265 
268 CLASS_DECLSPEC
269 Vector3 normalize(const Vector3& other);
270 
271 
272 inline Vector3 operator-(const Vector3& in)
273 {
274  return Vector3(-in.x(),-in.y(),-in.z());
275 }
276 
277 inline Vector3 operator*(double d,const Vector3& vec)
278 {
279  return Vector3(d*vec.x(),d*vec.y(),d*vec.z());
280 }
281 
282 
283 inline Vector3 operator+(const Vector3& vec0,const Vector3& vec1)
284 {
285  return Vector3(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
286 }
287 
288 inline Vector3 operator-(const Vector3& vec0,const Vector3& vec1)
289 {
290  return Vector3(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
291 }
292 
293 
294 
295 } // (namespace)
3D Vector
Definition: Vector3.h:27
double z() const
Get the z-value.
Definition: Vector3.h:100
void set(const double x_, const double y_, const double z_)
Set x,y,z.
double sqLength() const
Get the squared length of the vector.
double operator*(const Vector3 &other) const
Scalar product.
double getCartesian(int i) const
Get component i.
Vector3 & operator=(const Vector3 &other)
Assignment operator.
Definition: Vector3.h:213
Vector3(const Vector3 &v_)
Copy constructor.
double x() const
Get the x-value.
Definition: Vector3.h:81
void add(const Vector3 &other)
Add a Vector3 to the present one.
Definition: Vector3.h:117
Vector3(const double x_, const double y_, const double z_)
Constructor.
double getMaxComponent() const
Get max component.
Definition: Vector3.h:161
void reset()
reset
Definition: Vector3.h:71
Vector3()
Default constructor.
double getMaxAbsComponent() const
Get max absolute component.
int getMaxAbsIndex() const
Get max index.
Vector3 operator*(double val) const
Multiply by a scalar value.
Vector3 operator/(double val) const
Divide by a scalar value.
bool isDegenerate() const
isDegenerate
Definition: Vector3.h:52
void xyz(double &x_, double &y_, double &z_) const
Get x,y,z.
Definition: Vector3.h:61
double length() const
Get the length of the vector.
double y() const
Get the y-value.
Definition: Vector3.h:90
Definition: Point3.h:23
Vector3 normalize(const Vector3 &other)
Normalize.
Vector3 crossProduct(const Vector3 &vec0, const Vector3 &vec1)
Cross product.
Definition: Vector3.h:256