Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-gfe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sander, Oliver
dune-gfe
Commits
624486f2
Commit
624486f2
authored
19 years ago
by
Oliver Sander
Committed by
sander
19 years ago
Browse files
Options
Downloads
Patches
Plain Diff
A quaternion class
[[Imported from SVN: r736]]
parent
c48242c5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/quaternion.hh
+72
-0
72 additions, 0 deletions
src/quaternion.hh
with
72 additions
and
0 deletions
src/quaternion.hh
0 → 100644
+
72
−
0
View file @
624486f2
#ifndef QUATERNION_HH
#define QUATERNION_HH
#include
<dune/common/fvector.hh>
#include
<dune/common/exceptions.hh>
template
<
class
T
>
class
Quaternion
:
public
Dune
::
FieldVector
<
T
,
4
>
{
public:
/** \brief The exponential map from \f$ \mathfrak{so}(3) \f$ to \f$ SO(3) \f$
*/
static
Quaternion
<
T
>
exp
(
const
T
&
v0
,
const
T
&
v1
,
const
T
&
v2
)
{
Quaternion
<
T
>
q
;
T
normV
=
std
::
sqrt
(
v0
*
v0
+
v1
*
v1
+
v2
*
v2
);
T
sin
=
std
::
sin
(
normV
/
2
)
/
normV
;
q
[
0
]
=
sin
*
v0
;
q
[
1
]
=
sin
*
v1
;
q
[
2
]
=
sin
*
v2
;
q
[
3
]
=
std
::
cos
(
normV
/
2
);
return
q
;
}
/** \brief Right quaternion multiplication */
Quaternion
<
T
>
mult
(
const
Quaternion
<
T
>&
other
)
{
Quaternion
<
T
>
q
;
q
[
0
]
=
(
*
this
)[
3
]
*
other
[
0
]
-
(
*
this
)[
2
]
*
other
[
1
]
+
(
*
this
)[
1
]
*
other
[
2
]
+
(
*
this
)[
0
]
*
other
[
3
];
q
[
1
]
=
(
*
this
)[
2
]
*
other
[
0
]
+
(
*
this
)[
3
]
*
other
[
1
]
-
(
*
this
)[
0
]
*
other
[
2
]
+
(
*
this
)[
1
]
*
other
[
3
];
q
[
2
]
=
-
(
*
this
)[
1
]
*
other
[
0
]
+
(
*
this
)[
0
]
*
other
[
1
]
+
(
*
this
)[
3
]
*
other
[
2
]
+
(
*
this
)[
2
]
*
other
[
3
];
q
[
3
]
=
-
(
*
this
)[
0
]
*
other
[
0
]
-
(
*
this
)[
1
]
*
other
[
1
]
-
(
*
this
)[
2
]
*
other
[
2
]
+
(
*
this
)[
3
]
*
other
[
3
];
return
q
;
}
/** \brief Return the tripel of director vectors represented by a unit quaternion
The formulas are taken from Dichmann, Li, Maddocks, (2.6.4), (2.6.5), (2.6.6)
*/
Dune
::
FieldVector
<
T
,
3
>
director
(
int
i
)
const
{
Dune
::
FieldVector
<
T
,
3
>
d
;
const
Dune
::
FieldVector
<
T
,
4
>&
q
=
*
this
;
// simpler notation
if
(
i
==
0
)
{
d
[
0
]
=
q
[
0
]
*
q
[
0
]
-
q
[
1
]
*
q
[
1
]
-
q
[
2
]
*
q
[
2
]
+
q
[
3
]
*
q
[
3
];
d
[
1
]
=
2
*
(
q
[
0
]
*
q
[
1
]
+
q
[
2
]
*
q
[
3
]);
d
[
2
]
=
2
*
(
q
[
0
]
*
q
[
2
]
-
q
[
1
]
*
q
[
3
]);
}
else
if
(
i
==
1
)
{
d
[
0
]
=
2
*
(
q
[
0
]
*
q
[
1
]
-
q
[
2
]
*
q
[
3
]);
d
[
1
]
=
-
q
[
0
]
*
q
[
0
]
+
q
[
1
]
*
q
[
1
]
-
q
[
2
]
*
q
[
2
]
+
q
[
3
]
*
q
[
3
];
d
[
2
]
=
2
*
(
q
[
1
]
*
q
[
2
]
+
q
[
0
]
*
q
[
3
]);
}
else
if
(
i
==
2
)
{
d
[
0
]
=
2
*
(
q
[
0
]
*
q
[
2
]
+
q
[
1
]
*
q
[
3
]);
d
[
1
]
=
2
*
(
q
[
1
]
*
q
[
2
]
-
q
[
0
]
*
q
[
3
]);
d
[
2
]
=
-
q
[
0
]
*
q
[
0
]
-
q
[
1
]
*
q
[
1
]
+
q
[
2
]
*
q
[
2
]
+
q
[
3
]
*
q
[
3
];
}
else
DUNE_THROW
(
Dune
::
Exception
,
"Nonexisting director "
<<
i
<<
" requested!"
);
return
d
;
}
/** \brief Turn quaternion into a unit quaternion by dividing by its Euclidean norm */
void
normalize
()
{
(
*
this
)
/=
this
->
two_norm
();
}
};
#endif
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