39 |
|
#include "Vector.hpp" |
40 |
|
|
41 |
|
namespace oopse { |
42 |
+ |
|
43 |
+ |
/** |
44 |
+ |
* @class Vector3 Vector3.hpp "math/Vector3.hpp" |
45 |
+ |
* @brief |
46 |
+ |
*/ |
47 |
+ |
|
48 |
+ |
template<typename Real> |
49 |
+ |
class Vector3 : public Vector<Real, 3>{ |
50 |
+ |
public: |
51 |
|
|
52 |
+ |
Vector3() : Vector<Real, 3>(){} |
53 |
+ |
|
54 |
+ |
/** Constructs and initializes a Vector3 from x, y, z coordinates */ |
55 |
+ |
inline Vector3( double x, double y, double z) { |
56 |
+ |
data_[0] = x; |
57 |
+ |
data_[1] = y; |
58 |
+ |
data_[2] = z; |
59 |
+ |
} |
60 |
+ |
|
61 |
+ |
inline Vector3(const Vector<Real, 3>& v) : Vector<Real, 3>(v) {} |
62 |
+ |
|
63 |
+ |
inline Vector3<Real>& operator = (const Vector<Real, 3>& v) { |
64 |
+ |
if (this == &v) { return *this; } |
65 |
+ |
Vector<Real, 3>::operator=(v); |
66 |
+ |
return *this; |
67 |
+ |
} |
68 |
+ |
|
69 |
|
/** |
70 |
< |
* @class Vector3 Vector3.hpp "math/Vector3.hpp" |
71 |
< |
* @brief |
70 |
> |
* Retunrs reference of the first element of Vector3. |
71 |
> |
* @return reference of the first element of Vector3 |
72 |
|
*/ |
73 |
+ |
inline Real& x() { return data_[0];} |
74 |
|
|
48 |
– |
template<typename Real> |
49 |
– |
class Vector3 : public Vector<Real, 3>{ |
50 |
– |
public: |
51 |
– |
|
52 |
– |
Vector3() : Vector<Real, 3>(){} |
53 |
– |
|
54 |
– |
/** Constructs and initializes a Vector3 from x, y, z coordinates */ |
55 |
– |
inline Vector3( double x, double y, double z) { |
56 |
– |
data_[0] = x; |
57 |
– |
data_[1] = y; |
58 |
– |
data_[2] = z; |
59 |
– |
} |
60 |
– |
|
61 |
– |
inline Vector3(const Vector<Real, 3>& v) : Vector<Real, 3>(v) {} |
62 |
– |
|
63 |
– |
inline Vector3<Real>& operator = (const Vector<Real, 3>& v) { |
64 |
– |
if (this == &v) { return *this; } |
65 |
– |
Vector<Real, 3>::operator=(v); |
66 |
– |
return *this; |
67 |
– |
} |
68 |
– |
|
69 |
– |
/** |
70 |
– |
* Retunrs reference of the first element of Vector3. |
71 |
– |
* @return reference of the first element of Vector3 |
72 |
– |
*/ |
73 |
– |
inline Real& x() { return data_[0];} |
74 |
– |
|
75 |
– |
/** |
76 |
– |
* Retunrs the first element of Vector3. |
77 |
– |
* @return the first element of Vector3 |
78 |
– |
*/ |
79 |
– |
inline Real x() const { return data_[0];} |
80 |
– |
|
81 |
– |
/** |
82 |
– |
* Retunrs reference of the second element of Vector3. |
83 |
– |
* @return reference of the second element of Vector3 |
84 |
– |
*/ |
85 |
– |
inline Real& y() { return data_[1];} |
86 |
– |
|
87 |
– |
/** |
88 |
– |
* Retunrs the second element of Vector3. |
89 |
– |
* @return c the second element of Vector3 |
90 |
– |
*/ |
91 |
– |
inline Real y() const { return data_[1];} |
92 |
– |
|
93 |
– |
/** |
94 |
– |
* Retunrs reference of the third element of Vector3. |
95 |
– |
* @return reference of the third element of Vector3 |
96 |
– |
*/ |
97 |
– |
inline Real& z() { return data_[2];} |
98 |
– |
|
99 |
– |
/** |
100 |
– |
* Retunrs the third element of Vector3. |
101 |
– |
* @return f the third element of Vector3 |
102 |
– |
*/ |
103 |
– |
inline Real z() const { return data_[2];} |
104 |
– |
|
105 |
– |
}; |
106 |
– |
|
75 |
|
/** |
76 |
< |
* Returns the cross product of two Vectors |
77 |
< |
* @param v1 first vector |
110 |
< |
* @param v2 second vector |
111 |
< |
* @return the cross product of v1 and v2 |
112 |
< |
* @see #vector::dot |
76 |
> |
* Retunrs the first element of Vector3. |
77 |
> |
* @return the first element of Vector3 |
78 |
|
*/ |
79 |
< |
template<typename Real> |
80 |
< |
Vector3<Real> cross( const Vector3<Real>& v1, const Vector3<Real>& v2 ) { |
81 |
< |
Vector3<Real> result; |
82 |
< |
|
83 |
< |
result.x() = v1.y() * v2.z() - v1.z() * v2.y(); |
84 |
< |
result.y() = v1.z() * v2.x() - v1.x() * v2.z(); |
85 |
< |
result.z() = v1.x() * v2.y() - v1.y() * v2.x(); |
86 |
< |
|
87 |
< |
return result; |
88 |
< |
} |
89 |
< |
|
90 |
< |
|
91 |
< |
template Vector3<double> Vector3d; |
92 |
< |
|
79 |
> |
inline Real x() const { return data_[0];} |
80 |
> |
|
81 |
> |
/** |
82 |
> |
* Retunrs reference of the second element of Vector3. |
83 |
> |
* @return reference of the second element of Vector3 |
84 |
> |
*/ |
85 |
> |
inline Real& y() { return data_[1];} |
86 |
> |
|
87 |
> |
/** |
88 |
> |
* Retunrs the second element of Vector3. |
89 |
> |
* @return c the second element of Vector3 |
90 |
> |
*/ |
91 |
> |
inline Real y() const { return data_[1];} |
92 |
> |
|
93 |
> |
/** |
94 |
> |
* Retunrs reference of the third element of Vector3. |
95 |
> |
* @return reference of the third element of Vector3 |
96 |
> |
*/ |
97 |
> |
inline Real& z() { return data_[2];} |
98 |
> |
|
99 |
> |
/** |
100 |
> |
* Retunrs the third element of Vector3. |
101 |
> |
* @return f the third element of Vector3 |
102 |
> |
*/ |
103 |
> |
inline Real z() const { return data_[2];} |
104 |
> |
|
105 |
> |
}; |
106 |
> |
|
107 |
> |
/** |
108 |
> |
* Returns the cross product of two Vectors |
109 |
> |
* @param v1 first vector |
110 |
> |
* @param v2 second vector |
111 |
> |
* @return the cross product of v1 and v2 |
112 |
> |
* @see #vector::dot |
113 |
> |
*/ |
114 |
> |
template<typename Real> |
115 |
> |
Vector3<Real> cross( const Vector3<Real>& v1, const Vector3<Real>& v2 ) { |
116 |
> |
Vector3<Real> result; |
117 |
> |
|
118 |
> |
result.x() = v1.y() * v2.z() - v1.z() * v2.y(); |
119 |
> |
result.y() = v1.z() * v2.x() - v1.x() * v2.z(); |
120 |
> |
result.z() = v1.x() * v2.y() - v1.y() * v2.x(); |
121 |
> |
|
122 |
> |
return result; |
123 |
> |
} |
124 |
> |
|
125 |
> |
typedef Vector3<double> Vector3d; |
126 |
> |
|
127 |
|
} |
128 |
|
|
130 |
– |
|
129 |
|
#endif |