Skip to content
Snippets Groups Projects
Commit dd5b2f47 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

clang-format

parent 1d29ce09
No related branches found
No related tags found
1 merge request!852Reimplement RotMatrix using quaternions instead of generic 3x3 matrices
Pipeline #64418 failed
......@@ -18,7 +18,10 @@
#include <utility>
RotMatrix::RotMatrix(double x_, double y_, double z_, double s_)
: x(x_), y(y_), z(z_), s(s_)
: x(x_)
, y(y_)
, z(z_)
, s(s_)
{
}
......@@ -29,17 +32,17 @@ RotMatrix::RotMatrix()
RotMatrix RotMatrix::createRotateX(double phi)
{
return { sin(phi/2), 0, 0, cos(phi/2) };
return {sin(phi / 2), 0, 0, cos(phi / 2)};
}
RotMatrix RotMatrix::createRotateY(double phi)
{
return { 0, sin(phi/2), 0, cos(phi/2) };
return {0, sin(phi / 2), 0, cos(phi / 2)};
}
RotMatrix RotMatrix::createRotateZ(double phi)
{
return { 0, 0, sin(phi/2), cos(phi/2) };
return {0, 0, sin(phi / 2), cos(phi / 2)};
}
RotMatrix RotMatrix::createRotateEuler(double alpha, double beta, double gamma)
......@@ -52,15 +55,15 @@ RotMatrix RotMatrix::createRotateEuler(double alpha, double beta, double gamma)
void RotMatrix::calculateEulerAngles(double* p_alpha, double* p_beta, double* p_gamma) const
{
double m00 = (-1+2*x*x+2*s*s);
double m01 = 2*(x*y-z*s);
double m02 = 2*(x*z+y*s);
double m10 = 2*(y*x+z*s);
double m11 = (-1+2*y*y+2*s*s);
double m12 = 2*(y*z-x*s);
double m20 = 2*(z*x-y*s);
double m21 = 2*(z*y+x*s);
double m22 = (-1+2*z*z+2*s*s);
double m00 = (-1 + 2 * x * x + 2 * s * s);
double m01 = 2 * (x * y - z * s);
double m02 = 2 * (x * z + y * s);
double m10 = 2 * (y * x + z * s);
double m11 = (-1 + 2 * y * y + 2 * s * s);
double m12 = 2 * (y * z - x * s);
double m20 = 2 * (z * x - y * s);
double m21 = 2 * (z * y + x * s);
double m22 = (-1 + 2 * z * z + 2 * s * s);
*p_beta = std::acos(m22);
// First check if second angle is zero or pi
......@@ -76,32 +79,35 @@ void RotMatrix::calculateEulerAngles(double* p_alpha, double* p_beta, double* p_
double RotMatrix::calculateRotateXAngle() const
{
ASSERT(isXRotation());
return 2*atan2(x, s);
return 2 * atan2(x, s);
}
double RotMatrix::calculateRotateYAngle() const
{
ASSERT(isYRotation());
return 2*atan2(y, s);
return 2 * atan2(y, s);
}
double RotMatrix::calculateRotateZAngle() const
{
ASSERT(isZRotation());
return 2*atan2(z, s);
return 2 * atan2(z, s);
}
RotMatrix RotMatrix::getInverse() const
{
return { -x, -y, -z, s };
return {-x, -y, -z, s};
}
template <class T>
T RotMatrix::transformed(const T& v) const
{
auto xf = (-1+2*x*x+2*s*s)*v.x() + 2*(x*y-z*s)*v.y() + 2*(x*z+y*s)*v.z();
auto yf = (-1+2*y*y+2*s*s)*v.y() + 2*(y*z-x*s)*v.z() + 2*(y*x+z*s)*v.x();
auto zf = (-1+2*z*z+2*s*s)*v.z() + 2*(z*x-y*s)*v.x() + 2*(z*y+x*s)*v.y();
auto xf = (-1 + 2 * x * x + 2 * s * s) * v.x() + 2 * (x * y - z * s) * v.y()
+ 2 * (x * z + y * s) * v.z();
auto yf = (-1 + 2 * y * y + 2 * s * s) * v.y() + 2 * (y * z - x * s) * v.z()
+ 2 * (y * x + z * s) * v.x();
auto zf = (-1 + 2 * z * z + 2 * s * s) * v.z() + 2 * (z * x - y * s) * v.x()
+ 2 * (z * y + x * s) * v.y();
return T(xf, yf, zf);
}
......@@ -125,16 +131,13 @@ RotMatrix* RotMatrix::clone() const
RotMatrix RotMatrix::operator*(const RotMatrix& o) const
{
return {
s*o.x+x*o.s+y*o.z-z*o.y,
s*o.y+y*o.s+z*o.x-x*o.z,
s*o.z+z*o.s+x*o.y-y*o.x,
s*o.s-x*o.x-y*o.y-z*o.z };
return {s * o.x + x * o.s + y * o.z - z * o.y, s * o.y + y * o.s + z * o.x - x * o.z,
s * o.z + z * o.s + x * o.y - y * o.x, s * o.s - x * o.x - y * o.y - z * o.z};
}
bool RotMatrix::operator==(const RotMatrix& o) const
{
return x==o.x && y==o.y && z==o.z && s==o.s;
return x == o.x && y == o.y && z == o.z && s == o.s;
}
RotMatrix::ERotationType RotMatrix::getRotationType() const
......@@ -150,20 +153,20 @@ RotMatrix::ERotationType RotMatrix::getRotationType() const
bool RotMatrix::isIdentity() const
{
return x==0 && y==0 && z==0;
return x == 0 && y == 0 && z == 0;
}
bool RotMatrix::isXRotation() const
{
return y==0 && z==0;
return y == 0 && z == 0;
}
bool RotMatrix::isYRotation() const
{
return z==0 && x==0;
return z == 0 && x == 0;
}
bool RotMatrix::isZRotation() const
{
return x==0 && y==0;
return x == 0 && y == 0;
}
......@@ -5,13 +5,14 @@ class RotMatrixTest : public ::testing::Test {
protected:
const double epsilon = 1e-12;
const double w0 = M_PI/5;
const double w1 = M_PI/7;
const double w2 = M_PI/11;
const double w0 = M_PI / 5;
const double w1 = M_PI / 7;
const double w2 = M_PI / 11;
const RotMatrix mEul = RotMatrix::createRotateEuler(w0, w1, w2);
void InversionTest(const RotMatrix& mRot, const R3& a0) {
void InversionTest(const RotMatrix& mRot, const R3& a0)
{
const RotMatrix mInv = mRot.getInverse();
......@@ -66,20 +67,20 @@ TEST_F(RotMatrixTest, RecoverEulerAngles)
TEST_F(RotMatrixTest, InvertXMatrix)
{
InversionTest(RotMatrix::createRotateX(M_PI / 7.), R3(4,5,6));
InversionTest(RotMatrix::createRotateX(M_PI / 7.), R3(4, 5, 6));
}
TEST_F(RotMatrixTest, InvertYMatrix)
{
InversionTest(RotMatrix::createRotateY(M_PI / 7.), R3(4,5,6));
InversionTest(RotMatrix::createRotateY(M_PI / 7.), R3(4, 5, 6));
}
TEST_F(RotMatrixTest, InvertZMatrix)
{
InversionTest(RotMatrix::createRotateZ(M_PI / 7.), R3(4,5,6));
InversionTest(RotMatrix::createRotateZ(M_PI / 7.), R3(4, 5, 6));
}
TEST_F(RotMatrixTest, InvertEulerMatrix)
{
InversionTest(mEul, R3(3,4,7));
InversionTest(mEul, R3(3, 4, 7));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment