Algebra3D
Algebra for 3D transformations
 All Classes Namespaces Files Functions Variables Typedefs Macros
Vector3.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Jaroslaw Glowacki
3  * jarek (dot) glowacki (at) gmail (dot) com
4  *
5  * This file is part of algebra3d.
6  *
7  * algebra3d is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * algebra3d is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with algebra3d. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 #ifndef _VECTOR_H_
28 #define _VECTOR_H_
29 
30 #include<algebra3d/global.h>
31 
32 namespace algebra3d {
33 
34 /* Forward declarations */
35 template<class fpType>
36 class Matrix3;
37 template<class fpType>
38 class Quaternion;
39 
45 template<class fpType>
46 class Vector3 {
47  // Friendship declarations
48  template<class fpT>
49  friend std::istream& operator>>(std::istream &stream, Vector3<fpT> &vec);
50 
51 protected:
53  fpType data[3];
54 
55 public:
57  fpType &x;
59  fpType &y;
61  fpType &z;
62 
63 public:
67  Vector3();
68 
74  Vector3(const fpType * const data);
75 
83  Vector3(fpType x, fpType y, fpType z);
84 
90  Vector3(const Vector3<fpType> &vec);
91 
99  Vector3(const Vector3<fpType> &axis, fpType angle);
100 
107  Vector3(const Quaternion<fpType> &quat);
108 
116  Vector3(const Matrix3<fpType> &mat);
117 
121  virtual ~Vector3();
122 
129  virtual void set(const fpType *data);
130 
137  virtual void get(fpType *storage) const;
138 
145  virtual fpType dot(const Vector3<fpType> &vec) const;
146 
153  virtual Vector3<fpType> cross(const Vector3<fpType> &vec) const;
154 
161  virtual Matrix3<fpType> outer(const Vector3<fpType> &vec) const;
162 
169  virtual Matrix3<fpType> crossMatrix() const;
170 
176  virtual fpType getNorm() const;
177 
182  virtual void normalize();
183 
191  bool isZero() const;
192 
199  Vector3<fpType> getUnit() const;
200 
206  fpType getAngle() const;
207 
216 
222  virtual void operator=(const Vector3<fpType> &vec);
223 
232  virtual const fpType &operator[](int ind) const;
233 
242  virtual fpType &operator[](int ind);
243 
256  virtual bool compare(const Vector3<fpType> &vec, const fpType &precision =
257  PRECISION) const;
258 
268  virtual bool operator==(const Vector3<fpType> &vec) const;
269 
278  virtual bool operator!=(const Vector3<fpType> &vec) const;
279 
285  virtual void operator+=(const Vector3<fpType> &vec);
286 
293  virtual Vector3<fpType> operator+(const Vector3<fpType> &vec) const;
294 
300  virtual Vector3<fpType> operator-() const;
301 
307  virtual void operator-=(const Vector3<fpType> &vec);
308 
315  virtual Vector3<fpType> operator-(const Vector3<fpType> &vec) const;
316 
325  void operator*=(const Matrix3<fpType> &mat);
326 
335  virtual Vector3<fpType> operator*(const Matrix3<fpType> &mat) const;
336 
345  virtual Vector3<fpType> operator*(const Vector3<fpType> &vec) const;
346 
352  virtual void operator*=(const fpType &s);
353 
360  virtual Vector3<fpType> operator*(const fpType &s) const;
361 
367  virtual void operator/=(const fpType &s);
368 
376  virtual Vector3<fpType> operator/(const fpType &s) const;
377 };
378 
386 template<class fpType>
387 Vector3<fpType> operator*(const double &scale, const Vector3<fpType> &vec);
388 
396 template<class fpType>
397 Vector3<fpType> operator*(const float &scale, const Vector3<fpType> &vec);
398 
406 template<class fpType>
407 std::ostream& operator<<(std::ostream &stream, const Vector3<fpType> &vec);
408 
416 template<class fpType>
417 std::istream& operator>>(std::istream &stream, Vector3<fpType> &vec);
418 
425 
432 
433 } /* namespace algebra3d */
434 
435 #endif // _VECTOR_H_
virtual const fpType & operator[](int ind) const
fpType & z
Definition: Vector3.h:61
virtual void operator-=(const Vector3< fpType > &vec)
virtual bool operator!=(const Vector3< fpType > &vec) const
A class to store vectors of 3 elements.
Definition: Matrix3.h:35
std::istream & operator>>(std::istream &stream, Matrix3< fpType > &mat)
fpType & y
Definition: Vector3.h:59
virtual fpType dot(const Vector3< fpType > &vec) const
virtual fpType getNorm() const
virtual Vector3< fpType > operator-() const
Vector3< float > Vector3F
Definition: Vector3.h:431
virtual bool operator==(const Vector3< fpType > &vec) const
Vector3< double > Vector3D
Definition: Vector3.h:424
Matrix3< fpType > operator*(const double &scale, const Matrix3< fpType > &mat)
A class to store 3x3 rotation matrices.
Definition: Matrix3.h:48
virtual Matrix3< fpType > outer(const Vector3< fpType > &vec) const
virtual void operator=(const Vector3< fpType > &vec)
bool isZero() const
fpType data[3]
Definition: Vector3.h:53
#define PRECISION
Definition: global.h:51
virtual void operator/=(const fpType &s)
fpType getAngle() const
virtual Vector3< fpType > operator+(const Vector3< fpType > &vec) const
virtual Vector3< fpType > operator/(const fpType &s) const
fpType & x
Definition: Vector3.h:57
Vector3< fpType > getSqrtRotation() const
virtual void operator+=(const Vector3< fpType > &vec)
void operator*=(const Matrix3< fpType > &mat)
A class to store quaternions.
Definition: Matrix3.h:37
virtual bool compare(const Vector3< fpType > &vec, const fpType &precision=PRECISION) const
virtual Vector3< fpType > cross(const Vector3< fpType > &vec) const
virtual Vector3< fpType > operator*(const Matrix3< fpType > &mat) const
virtual void normalize()
Vector3< fpType > getUnit() const
virtual Matrix3< fpType > crossMatrix() const
virtual void set(const fpType *data)