Geom Software - C++ Programming and Geometry Libraries
FADEPLACEHOLDER Documentation pages v1.03
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 
32  Vector3(const double x_,const double y_,const double z_);
33 
38  Vector3();
39 
45  Vector3(const Vector3& v_);
46 
47 
52  Vector3 orthogonalVector() const;
53 
58  bool isDegenerate() const;
59 
60  inline void xyz(double& x_,double& y_,double& z_) const
61  {
62  x_=valX;
63  y_=valY;
64  z_=valZ;
65  }
66 
69  double x() const;
70 
73  double y() const;
74 
78  double z() const;
79 
82  void set(const double x_,const double y_,const double z_);
83 
84  void add(const Vector3& other)
85  {
86  valX+=other.valX;
87  valY+=other.valY;
88  valZ+=other.valZ;
89  }
90  void sub(const Vector3& other)
91  {
92  valX-=other.valX;
93  valY-=other.valY;
94  valZ-=other.valZ;
95  }
96  void div(double div)
97  {
98  valX/=div;
99  valY/=div;
100  valZ/=div;
101  }
102  void mul(double mul)
103  {
104  valX*=mul;
105  valY*=mul;
106  valZ*=mul;
107  }
108 
111  double sqLength() const;
112 
113 
114 
119  int getMaxAbsIndex() const;
120 
121 
125  double getMaxComponent() const
126  {
127  if(valX>=valY && valX>=valZ) return valX;
128  if(valY>=valZ) return valY;
129  else return valZ;
130  }
134  double getMaxAbsComponent() const;
135 
136 
141  double getCartesian(int i) const;
142 
143 
144 
148  double length() const;
149 
152  double operator*(const Vector3& other) const;
153 
154 
157  Vector3 operator*(double val) const;
158 
161  Vector3 operator/(double val) const;
162 
163 
164  Vector3& operator=(const Vector3& other);
165 
166 protected:
167  double valX;
168  double valY;
169  double valZ;
170 };
171 
172 
173 
174 
175 // Free functions
176 inline std::ostream &operator<<(std::ostream &stream, const Vector3& vec)
177 {
178  stream << "Vector3: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
179  return stream;
180 }
181 
182 
186 inline Vector3 crossProduct(const Vector3& vec0,const Vector3& vec1)
187 {
188 
189  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
190  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
191  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
192  return Vector3(x,y,z);
193 }
194 
195 
198 Vector3 normalize(const Vector3& other);
199 
200 
201 inline Vector3 operator-(const Vector3& in)
202 {
203  return Vector3(-in.x(),-in.y(),-in.z());
204 }
205 
206 
207 inline Vector3 operator*(double d,const Vector3& vec)
208 {
209  return Vector3(d*vec.x(),d*vec.y(),d*vec.z());
210 }
211 
212 
213 inline Vector3 operator+(const Vector3& vec0,const Vector3& vec1)
214 {
215  return Vector3(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
216 }
217 
218 
219 inline Vector3 operator-(const Vector3& vec0,const Vector3& vec1)
220 {
221  return Vector3(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
222 }
223 
224 
225 } // (namespace)
double z() const
Get the z-value.
double x() const
Get the x-value.
Definition: Point3.h:23
double getMaxComponent() const
Get max component.
Definition: Vector3.h:125
3D Vector
Definition: Vector3.h:26
double y() const
Get the y-value.