Skip to content

Commit

Permalink
move Hat and Dyadic product to Matrix class
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Dec 4, 2016
1 parent 6cde253 commit 3565d4e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 47 deletions.
76 changes: 76 additions & 0 deletions src/Base/Matrix.cpp
Expand Up @@ -871,3 +871,79 @@ std::string Matrix4D::analyse(void) const
}
return text;
}

Matrix4D& Matrix4D::Outer(const Vector3f& rV1, const Vector3f& rV2)
{
setToUnity();

dMtrx4D[0][0] = rV1.x * rV2.x;
dMtrx4D[0][1] = rV1.x * rV2.y;
dMtrx4D[0][2] = rV1.x * rV2.z;

dMtrx4D[1][0] = rV1.y * rV2.x;
dMtrx4D[1][1] = rV1.y * rV2.y;
dMtrx4D[1][2] = rV1.y * rV2.z;

dMtrx4D[2][0] = rV1.z * rV2.x;
dMtrx4D[2][1] = rV1.z * rV2.y;
dMtrx4D[2][2] = rV1.z * rV2.z;

return *this;
}

Matrix4D& Matrix4D::Outer(const Vector3d& rV1, const Vector3d& rV2)
{
setToUnity();

dMtrx4D[0][0] = rV1.x * rV2.x;
dMtrx4D[0][1] = rV1.x * rV2.y;
dMtrx4D[0][2] = rV1.x * rV2.z;

dMtrx4D[1][0] = rV1.y * rV2.x;
dMtrx4D[1][1] = rV1.y * rV2.y;
dMtrx4D[1][2] = rV1.y * rV2.z;

dMtrx4D[2][0] = rV1.z * rV2.x;
dMtrx4D[2][1] = rV1.z * rV2.y;
dMtrx4D[2][2] = rV1.z * rV2.z;

return *this;
}

Matrix4D& Matrix4D::Hat(const Vector3f& rV)
{
setToUnity();

dMtrx4D[0][0] = 0.0;
dMtrx4D[0][1] = -rV.z;
dMtrx4D[0][2] = rV.y;

dMtrx4D[1][0] = rV.z;
dMtrx4D[1][1] = 0.0;
dMtrx4D[1][2] = -rV.x;

dMtrx4D[2][0] = -rV.y;
dMtrx4D[2][1] = rV.x;
dMtrx4D[2][2] = 0.0;

return *this;
}

Matrix4D& Matrix4D::Hat(const Vector3d& rV)
{
setToUnity();

dMtrx4D[0][0] = 0.0;
dMtrx4D[0][1] = -rV.z;
dMtrx4D[0][2] = rV.y;

dMtrx4D[1][0] = rV.z;
dMtrx4D[1][1] = 0.0;
dMtrx4D[1][2] = -rV.x;

dMtrx4D[2][0] = -rV.y;
dMtrx4D[2][1] = rV.x;
dMtrx4D[2][2] = 0.0;

return *this;
}
6 changes: 6 additions & 0 deletions src/Base/Matrix.h
Expand Up @@ -95,6 +95,12 @@ class BaseExport Matrix4D
double determinant() const;
/// Analyse the transformation
std::string analyse(void) const;
/// Outer product (Dyadic product)
Matrix4D& Outer(const Vector3f& rV1, const Vector3f& rV2);
Matrix4D& Outer(const Vector3d& rV1, const Vector3d& rV2);
/// Hat operator (skew symmetric)
Matrix4D& Hat(const Vector3f& rV);
Matrix4D& Hat(const Vector3d& rV);
//@}

void getMatrix (double dMtrx[16]) const;
Expand Down
40 changes: 1 addition & 39 deletions src/Base/Vector3D.cpp
Expand Up @@ -24,7 +24,7 @@
#include "PreCompiled.h"
#include "Tools.h"
#include "Vector3D.h"
#include "Matrix.h"

using namespace Base;

template <class _Precision>
Expand Down Expand Up @@ -192,44 +192,6 @@ Vector3<_Precision> Vector3<_Precision>::Cross(const Vector3<_Precision>& rcVct)
return cVctRes;
}

template <class _Precision>
Matrix4D Vector3<_Precision>::Outer(const Vector3<_Precision>& rcVct) const
{
Matrix4D mat;
mat[0][0] = x * rcVct.x;
mat[0][1] = x * rcVct.y;
mat[0][2] = x * rcVct.z;

mat[1][0] = y * rcVct.x;
mat[1][1] = y * rcVct.y;
mat[1][2] = y * rcVct.z;

mat[2][0] = z * rcVct.x;
mat[2][1] = z * rcVct.y;
mat[2][2] = z * rcVct.z;

return mat;
}

template <class _Precision>
Matrix4D Vector3<_Precision>::Hat(void) const
{
Matrix4D mat;
mat[0][0] = 0.0;
mat[0][1] = -z;
mat[0][2] = y;

mat[1][0] = z;
mat[1][1] = 0.0;
mat[1][2] = -x;

mat[2][0] = -y;
mat[2][1] = x;
mat[2][2] = 0.0;

return mat;
}

template <class _Precision>
bool Vector3<_Precision>::operator != (const Vector3<_Precision>& rcVct) const
{
Expand Down
8 changes: 0 additions & 8 deletions src/Base/Vector3D.h
Expand Up @@ -73,10 +73,6 @@ struct float_traits<double> {
static inline float_type maximum() { return DBL_MAX; }
};

class Matrix4D;
//#include <Base/Matrix.h>


/** The Vector Base class. */
template <class _Precision>
class Vector3
Expand Down Expand Up @@ -130,10 +126,6 @@ class Vector3
Vector3 operator % (const Vector3<_Precision>& rcVct) const;
/// Cross product
Vector3 Cross (const Vector3<_Precision>& rcVct) const;
/// Outer product
Matrix4D Outer(const Vector3<_Precision>& rcVct) const;
/// Hat operator (skew symmetric)
Matrix4D Hat(void) const;

/// Comparing for inequality
bool operator != (const Vector3<_Precision>& rcVct) const;
Expand Down

0 comments on commit 3565d4e

Please sign in to comment.