Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.16
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 
201 Vector3 operator*(double val) const;
202 
207 Vector3 operator/(double val) const;
208 
211  Vector3& operator=(const Vector3& other)
212  {
213  valX=other.valX;
214  valY=other.valY;
215  valZ=other.valZ;
216  return *this;
217  }
218 
219 Vector3& operator+=(const Vector3& other);
220 Vector3& operator-=(const Vector3& other);
221 Vector3& operator/=(double div);
222 Vector3& operator*=(double mul);
223 
224 
225 
226 protected:
227 
228 double valX;
229 double valY;
230 double valZ;
231 };
232 
233 
234 
235 
236 // Free functions
237 inline std::ostream &operator<<(std::ostream &stream, const Vector3& vec)
238 {
239  stream << "Vector3: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
240  return stream;
241 }
242 
243 
246 inline Vector3 crossProduct(const Vector3& vec0,const Vector3& vec1)
247 {
248 
249  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
250  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
251  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
252  return Vector3(x,y,z);
253 }
254 
255 
258 CLASS_DECLSPEC
259 Vector3 normalize(const Vector3& other);
260 
261 
262 inline Vector3 operator-(const Vector3& in)
263 {
264  return Vector3(-in.x(),-in.y(),-in.z());
265 }
266 
267 inline Vector3 operator*(double d,const Vector3& vec)
268 {
269  return Vector3(d*vec.x(),d*vec.y(),d*vec.z());
270 }
271 
272 
273 inline Vector3 operator+(const Vector3& vec0,const Vector3& vec1)
274 {
275  return Vector3(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
276 }
277 
278 inline Vector3 operator-(const Vector3& vec0,const Vector3& vec1)
279 {
280  return Vector3(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
281 }
282 
283 
284 
285 } // (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:211
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:246