Geom Software - C++ Programming and Geometry Libraries
WOF Documentation pages v1.04
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 
40 Vector3();
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 double x() const;
70 
74 double y() const;
75 
80 double z() const;
81 
88 void set(const double x_,const double y_,const double z_);
89 
94 void add(const Vector3& other)
95 {
96  valX+=other.valX;
97  valY+=other.valY;
98  valZ+=other.valZ;
99 }
100 void sub(const Vector3& other)
101 {
102  valX-=other.valX;
103  valY-=other.valY;
104  valZ-=other.valZ;
105 }
106 void div(double div)
107 {
108  valX/=div;
109  valY/=div;
110  valZ/=div;
111 }
112 void mul(double mul)
113 {
114  valX*=mul;
115  valY*=mul;
116  valZ*=mul;
117 }
118 
123 double sqLength() const;
124 
125 
126 
131 int getMaxAbsIndex() const;
132 
133 
138 double getMaxComponent() const
139 {
140  if(valX>=valY && valX>=valZ) return valX;
141  if(valY>=valZ) return valY;
142  else return valZ;
143 }
148 double getMaxAbsComponent() const;
149 
150 
156 double getCartesian(int i) const;
157 
158 
159 
164 double length() const;
165 
170 double operator*(const Vector3& other) const;
171 
172 
177 Vector3 operator*(double val) const;
178 
183 Vector3 operator/(double val) const;
184 
189 Vector3& operator=(const Vector3& other);
190 
191 protected:
192 
193 double valX;
194 double valY;
195 double valZ;
196 };
197 
198 
199 
200 
201 // Free functions
202 inline std::ostream &operator<<(std::ostream &stream, const Vector3& vec)
203 {
204  stream << "Vector3: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
205  return stream;
206 }
207 
208 
212 inline Vector3 crossProduct(const Vector3& vec0,const Vector3& vec1)
213 {
214 
215  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
216  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
217  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
218  return Vector3(x,y,z);
219 }
220 
221 
224 Vector3 normalize(const Vector3& other);
225 
226 
227 inline Vector3 operator-(const Vector3& in)
228 {
229  return Vector3(-in.x(),-in.y(),-in.z());
230 }
231 
232 
233 inline Vector3 operator*(double d,const Vector3& vec)
234 {
235  return Vector3(d*vec.x(),d*vec.y(),d*vec.z());
236 }
237 
238 
239 inline Vector3 operator+(const Vector3& vec0,const Vector3& vec1)
240 {
241  return Vector3(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
242 }
243 
244 
245 inline Vector3 operator-(const Vector3& vec0,const Vector3& vec1)
246 {
247  return Vector3(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
248 }
249 
250 
251 } // (namespace)
double z() const
Get the z-value.
double x() const
Get the x-value.
Vector3 normalize(const Vector3 &other)
Normalize.
Vector3 crossProduct(const Vector3 &vec0, const Vector3 &vec1)
Cross product.
Definition: Vector3.h:212
Definition: Point3.h:23
double getMaxComponent() const
Get max component.
Definition: Vector3.h:138
3D Vector
Definition: Vector3.h:26
void xyz(double &x_, double &y_, double &z_) const
Get x,y,z.
Definition: Vector3.h:58
void add(const Vector3 &other)
Add a Vector3 to the present one.
Definition: Vector3.h:94
double y() const
Get the y-value.