Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
dd5b2f47
Commit
dd5b2f47
authored
2 years ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
clang-format
parent
1d29ce09
No related branches found
No related tags found
1 merge request
!852
Reimplement RotMatrix using quaternions instead of generic 3x3 matrices
Pipeline
#64418
failed
2 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Base/Vector/RotMatrix.cpp
+33
-30
33 additions, 30 deletions
Base/Vector/RotMatrix.cpp
Tests/Unit/Base/RotMatrixTest.cpp
+9
-8
9 additions, 8 deletions
Tests/Unit/Base/RotMatrixTest.cpp
with
42 additions
and
38 deletions
Base/Vector/RotMatrix.cpp
+
33
−
30
View file @
dd5b2f47
...
...
@@ -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
;
}
This diff is collapsed.
Click to expand it.
Tests/Unit/Base/RotMatrixTest.cpp
+
9
−
8
View file @
dd5b2f47
...
...
@@ -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
));
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment