Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.14
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 
58 void xyz(double& x_,double& y_,double& z_) const
59 {
60  x_=valX;
61  y_=valY;
62  z_=valZ;
63 }
64 
69 inline double x() const
70 {
71  return valX;
72 }
73 
74 
78 inline double y() const
79 {
80  return valY;
81 }
82 
83 
84 
88 inline double z() const
89 {
90  return valZ;
91 }
92 
99 void set(const double x_,const double y_,const double z_);
100 
105 void add(const Vector3& other)
106 {
107  valX+=other.valX;
108  valY+=other.valY;
109  valZ+=other.valZ;
110 }
111 void sub(const Vector3& other)
112 {
113  valX-=other.valX;
114  valY-=other.valY;
115  valZ-=other.valZ;
116 }
117 void div(double div)
118 {
119  valX/=div;
120  valY/=div;
121  valZ/=div;
122 }
123 void mul(double mul)
124 {
125  valX*=mul;
126  valY*=mul;
127  valZ*=mul;
128 }
129 
134 double sqLength() const;
135 
136 
137 
142 int getMaxAbsIndex() const;
143 
144 
149 double getMaxComponent() const
150 {
151  if(valX>=valY && valX>=valZ) return valX;
152  if(valY>=valZ) return valY;
153  else return valZ;
154 }
159 double getMaxAbsComponent() const;
160 
161 
167 double getCartesian(int i) const;
168 
170 bool isNV() const;
171 
176 double length() const;
177 
182 double operator*(const Vector3& other) const;
183 
184 
189 Vector3 operator*(double val) const;
190 
195 Vector3 operator/(double val) const;
196 
201 Vector3& operator=(const Vector3& other);
202 
203 Vector3& operator+=(const Vector3& other);
204 Vector3& operator-=(const Vector3& other);
205 Vector3& operator/=(double div);
206 Vector3& operator*=(double mul);
207 
208 
209 
210 protected:
211 
212 double valX;
213 double valY;
214 double valZ;
215 };
216 
217 
218 
219 
220 // Free functions
221 inline std::ostream &operator<<(std::ostream &stream, const Vector3& vec)
222 {
223  stream << "Vector3: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
224  return stream;
225 }
226 
227 
230 inline Vector3 crossProduct(const Vector3& vec0,const Vector3& vec1)
231 {
232 
233  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
234  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
235  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
236  return Vector3(x,y,z);
237 }
238 
239 
242 CLASS_DECLSPEC
243 Vector3 normalize(const Vector3& other);
244 
245 
246 inline Vector3 operator-(const Vector3& in)
247 {
248  return Vector3(-in.x(),-in.y(),-in.z());
249 }
250 
251 
252 inline Vector3 operator*(double d,const Vector3& vec)
253 {
254  return Vector3(d*vec.x(),d*vec.y(),d*vec.z());
255 }
256 
257 
258 inline Vector3 operator+(const Vector3& vec0,const Vector3& vec1)
259 {
260  return Vector3(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
261 }
262 
263 
264 inline Vector3 operator-(const Vector3& vec0,const Vector3& vec1)
265 {
266  return Vector3(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
267 }
268 
269 
270 } // (namespace)
3D Vector
Definition: Vector3.h:27
double z() const
Get the z-value.
Definition: Vector3.h:88
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)
Equality operator.
Vector3(const Vector3 &v_)
Copy constructor.
double x() const
Get the x-value.
Definition: Vector3.h:69
void add(const Vector3 &other)
Add a Vector3 to the present one.
Definition: Vector3.h:105
Vector3(const double x_, const double y_, const double z_)
Constructor.
double getMaxComponent() const
Get max component.
Definition: Vector3.h:149
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
void xyz(double &x_, double &y_, double &z_) const
Get x,y,z.
Definition: Vector3.h:58
double length() const
Get the length of the vector.
double y() const
Get the y-value.
Definition: Vector3.h:78
Definition: Point3.h:23
Vector3 normalize(const Vector3 &other)
Normalize.
Vector3 crossProduct(const Vector3 &vec0, const Vector3 &vec1)
Cross product.
Definition: Vector3.h:230