Revision fd9de024
| utility/vector.h | ||
|---|---|---|
| 114 | 114 |
return ret; |
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 |
Vector cross(Vector v) |
|
| 118 |
{
|
|
| 119 |
Vector ret; |
|
| 120 |
|
|
| 121 |
// The cross product is only valid for vectors with 3 dimensions, |
|
| 122 |
// with the exception of higher dimensional stuff that is beyond the intended scope of this library |
|
| 123 |
if(N != 3) |
|
| 124 |
return ret; |
|
| 125 |
|
|
| 126 |
ret.p_vec[0] = (p_vec[1] * v.p_vec[2]) - (p_vec[2] * v.p_vec[1]); |
|
| 127 |
ret.p_vec[1] = (p_vec[2] * v.p_vec[0]) - (p_vec[0] * v.p_vec[2]); |
|
| 128 |
ret.p_vec[2] = (p_vec[0] * v.p_vec[1]) - (p_vec[1] * v.p_vec[0]); |
|
| 129 |
return ret; |
|
| 130 |
} |
|
| 117 |
// The cross product is only valid for vectors with 3 dimensions, |
|
| 118 |
// with the exception of higher dimensional stuff that is beyond |
|
| 119 |
// the intended scope of this library. |
|
| 120 |
// Only a definition for N==3 is given below this class, using |
|
| 121 |
// cross() with another value for N will result in a link error. |
|
| 122 |
Vector cross(const Vector& v) const; |
|
| 131 | 123 |
|
| 132 | 124 |
Vector scale(double scalar) const |
| 133 | 125 |
{
|
| ... | ... | |
| 226 | 218 |
}; |
| 227 | 219 |
|
| 228 | 220 |
|
| 229 |
}; |
|
| 221 |
template <> |
|
| 222 |
inline Vector<3> Vector<3>::cross(const Vector& v) const |
|
| 223 |
{
|
|
| 224 |
return Vector( |
|
| 225 |
p_vec[1] * v.p_vec[2] - p_vec[2] * v.p_vec[1], |
|
| 226 |
p_vec[2] * v.p_vec[0] - p_vec[0] * v.p_vec[2], |
|
| 227 |
p_vec[0] * v.p_vec[1] - p_vec[1] * v.p_vec[0] |
|
| 228 |
); |
|
| 229 |
} |
|
| 230 |
|
|
| 231 |
} // namespace |
|
| 230 | 232 |
|
| 231 | 233 |
#endif |
Also available in: Unified diff