Subversion Repositories gelsvn

Rev

Rev 595 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 595 Rev 630
1
/* ----------------------------------------------------------------------- *
1
/* ----------------------------------------------------------------------- *
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 * Copyright (C) the authors and DTU Informatics
3
 * Copyright (C) the authors and DTU Informatics
4
 * For license and list of authors, see ../../doc/intro.pdf
4
 * For license and list of authors, see ../../doc/intro.pdf
5
 * @brief Abstract 3D floating point vector class
5
 * @brief Abstract 3D floating point vector class
6
 * ----------------------------------------------------------------------- */
6
 * ----------------------------------------------------------------------- */
7
 
7
 
8
/** @file ArithVec3Float.h
8
/** @file ArithVec3Float.h
9
 * @brief Abstract 3D floating point vector class
9
 * @brief Abstract 3D floating point vector class
10
 */
10
 */
11
 
11
 
12
#ifndef __CGLA__ARITHVEC3FLOAT_H__
12
#ifndef __CGLA__ARITHVEC3FLOAT_H__
13
#define __CGLA__ARITHVEC3FLOAT_H__
13
#define __CGLA__ARITHVEC3FLOAT_H__
14
 
14
 
15
#include "ArithVecFloat.h"
15
#include "ArithVecFloat.h"
16
 
16
 
17
namespace CGLA {
17
namespace CGLA {
18
 
18
 
19
	template<class T, class V>
19
	template<class T, class V>
20
	class ArithVec3Float: public ArithVecFloat<T,V,3>
20
	class ArithVec3Float: public ArithVecFloat<T,V,3>
21
	{
21
	{
22
	public:
22
	public:
23
 
23
 
24
		/// Construct a 3D float vector.
24
		/// Construct a 3D float vector.
25
		ArithVec3Float(T a, T b, T c): ArithVecFloat<T,V,3>(a,b,c) {}
25
		ArithVec3Float(T a, T b, T c): ArithVecFloat<T,V,3>(a,b,c) {}
26
 
26
 
27
		/// Construct a 3D float vector.
27
		/// Construct a 3D float vector.
28
		ArithVec3Float() {}
28
		ArithVec3Float() {}
29
 
29
 
30
		/** Get the vector in spherical coordinates.
30
		/** Get the vector in spherical coordinates.
31
				The first argument (theta) is inclination from the vertical axis.
31
				The first argument (theta) is inclination from the vertical axis.
32
				The second argument (phi) is the angle of rotation about the vertical 
32
				The second argument (phi) is the angle of rotation about the vertical 
33
				axis. The third argument (r) is the length of the vector. */
33
				axis. The third argument (r) is the length of the vector. */
34
		void get_spherical( T&, T&, T& ) const;
34
		void get_spherical( T&, T&, T& ) const;
35
 
35
 
36
		/** Assign the vector in spherical coordinates.
36
		/** Assign the vector in spherical coordinates.
37
				The first argument (theta) is inclination from the vertical axis.
37
				The first argument (theta) is inclination from the vertical axis.
38
				The second argument (phi) is the angle of rotation about the vertical 
38
				The second argument (phi) is the angle of rotation about the vertical 
39
				axis. The third argument (r) is the length of the vector. */
39
				axis. The third argument (r) is the length of the vector. */
40
		void set_spherical( T, T, T);
40
		void set_spherical( T, T, T);
41
		
41
		
42
	};
42
	};
43
 
43
 
44
	/// Returns cross product of arguments
44
	/// Returns cross product of arguments
45
	template<class T, class V>
45
	template<class T, class V>
46
	inline V cross( const ArithVec3Float<T,V>& x, 
46
	inline V cross( const ArithVec3Float<T,V>& x, 
47
									const ArithVec3Float<T,V>& y ) 
47
									const ArithVec3Float<T,V>& y ) 
48
	{
48
	{
49
		return V( x[1] * y[2] - x[2] * y[1], 
49
		return V( x[1] * y[2] - x[2] * y[1], 
50
							x[2] * y[0] - x[0] * y[2], 
50
							x[2] * y[0] - x[0] * y[2], 
51
							x[0] * y[1] - x[1] * y[0] );
51
							x[0] * y[1] - x[1] * y[0] );
52
	}
52
	}
53
 
53
 
54
	/** Compute basis of orthogonal plane.
54
	/** Compute basis of orthogonal plane.
55
			Given a vector compute two vectors that are orthogonal to it and 
55
			Given a vector compute two vectors that are orthogonal to it and 
56
			to each other. */
56
			to each other. */
57
	template<class T, class V>
57
	template<class T, class V>
58
	void orthogonal(const ArithVec3Float<T,V>&,
58
	void orthogonal(const ArithVec3Float<T,V>&,
59
									ArithVec3Float<T,V>&,
59
									ArithVec3Float<T,V>&,
60
									ArithVec3Float<T,V>&);
60
									ArithVec3Float<T,V>&);
61
 
61
 
62
  /** Build an orthonormal basis from a 3d unit vector [Frisvad 2012].
62
  /** Build an orthonormal basis from a 3d unit vector [Frisvad 2012].
63
      Given a unit vector compute two unit vectors that are orthogonal to
63
      Given a unit vector compute two unit vectors that are orthogonal to
64
      it and to each other. */
64
      it and to each other. */
65
  template<class T, class V>
65
  template<class T, class V>
66
  void onb(const ArithVec3Float<T,V>&,
66
  void onb(const ArithVec3Float<T,V>&,
67
           ArithVec3Float<T,V>&,
67
           ArithVec3Float<T,V>&,
68
           ArithVec3Float<T,V>&);
68
           ArithVec3Float<T,V>&);
69
}
69
}
70
 
70
 
71
#endif
71
#endif
72
 
72
 
73
 
73