mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
|
Defines useful geometry utilities and functions. More...
#include <cmath>
#include <Eigen/Dense>
#include <geometry_msgs/Point.h>
#include <geometry_msgs/Quaternion.h>
Go to the source code of this file.
Namespaces | |
mrs_lib | |
All mrs_lib functions, classes, variables and definitions are contained in this namespace. | |
Functions | |
template<int dims> | |
vec_t< dims+1 > | mrs_lib::geometry::toHomogenous (const vec_t< dims > &vec) |
template<typename T > | |
double | mrs_lib::geometry::headingFromRot (const T &rot) |
Returns the heading angle from the rotation. More... | |
double | mrs_lib::geometry::angleBetween (const vec2_t &a, const vec2_t &b) |
Returns the angle between two vectors, taking orientation into account. More... | |
double | mrs_lib::geometry::angleBetween (const vec3_t &a, const vec3_t &b) |
Returns the angle between two vectors, taking orientation into account. More... | |
anax_t | mrs_lib::geometry::angleaxisBetween (const vec3_t &a, const vec3_t &b, const double tolerance=1e-9) |
Returns the rotation between two vectors, represented as angle-axis. More... | |
quat_t | mrs_lib::geometry::quaternionBetween (const vec3_t &a, const vec3_t &b, const double tolerance=1e-9) |
Returns the rotation between two vectors, represented as a quaternion. More... | |
Eigen::Matrix3d | mrs_lib::geometry::rotationBetween (const vec3_t &a, const vec3_t &b, const double tolerance=1e-9) |
Returns the rotation between two vectors, represented as a rotation matrix. More... | |
double | mrs_lib::geometry::haversin (const double angle) |
computes the haversine (half of versine) for a given angle More... | |
double | mrs_lib::geometry::invHaversin (const double value) |
computes the inverse haversine angle for a given value More... | |
double | mrs_lib::geometry::solidAngle (double a, double b, double c) |
computes the solid angle for a spherical surface corresponding to a 'triangle' with edge lengths a, b, c More... | |
quat_t | mrs_lib::geometry::quaternionFromEuler (double x, double y, double z) |
create a quaternion from 3 provided Euler angles More... | |
quat_t | mrs_lib::geometry::quaternionFromEuler (const Eigen::Vector3d &euler) |
create a quaternion from Euler angles provided as a vector More... | |
quat_t | mrs_lib::geometry::quaternionFromHeading (const double heading) |
create a quaternion from heading More... | |
double | mrs_lib::geometry::cross (const vec2_t &a, const vec2_t b) |
Implementation of cross product for 2D vectors. More... | |
double | mrs_lib::geometry::dist (const vec2_t &a, const vec2_t &b) |
distnace between two 2D Eigen vectors More... | |
double | mrs_lib::geometry::dist (const vec3_t &a, const vec3_t &b) |
distnace between two 3D Eigen vectors More... | |
double | mrs_lib::geometry::triangleArea (const double a, const double b, const double c) |
uses Heron's formula to compute area of a given triangle using side lengths More... | |
double | mrs_lib::geometry::sphericalTriangleArea (Eigen::Vector3d a, Eigen::Vector3d b, Eigen::Vector3d c) |
compute the area of a 'triangle' drawn on a spherical surface More... | |
template<typename T > | |
mat3_t | mrs_lib::geometry::rotateCovariance (const mat3_t &cov, const T &rot) |
Returns the covariance rotated using the specified rotation. More... | |
Defines useful geometry utilities and functions.
anax_t mrs_lib::geometry::angleaxisBetween | ( | const vec3_t & | a, |
const vec3_t & | b, | ||
const double | tolerance = 1e-9 |
||
) |
Returns the rotation between two vectors, represented as angle-axis.
To avoid singularities, a tolerance
parameter is used:
tolerance
, a zero rotation is returned.tolerance
, a rotation is returned.a | vector from which the rotation starts. |
b | vector at which the rotation ends. |
a
to b
. double mrs_lib::geometry::angleBetween | ( | const vec2_t & | a, |
const vec2_t & | b | ||
) |
Returns the angle between two vectors, taking orientation into account.
This implementation uses atan2
instead of just acos
and thus it properly takes into account orientation of the vectors, returning angle in all four quadrants.
a | vector from which the angle will be measured. |
b | vector to which the angle will be measured. |
a
to b
. double mrs_lib::geometry::angleBetween | ( | const vec3_t & | a, |
const vec3_t & | b | ||
) |
Returns the angle between two vectors, taking orientation into account.
This implementation uses atan2
instead of just acos
and thus it properly takes into account orientation of the vectors, returning angle in all four quadrants.
a | vector from which the angle will be measured. |
b | vector to which the angle will be measured. |
a
to b
. double mrs_lib::geometry::cross | ( | const vec2_t & | a, |
const vec2_t | b | ||
) |
Implementation of cross product for 2D vectors.
Useful e.g. for finding the sine of an angle between two 2D vectors.
a | first vector of the cross product. |
b | second vector of the cross product. |
a
to b
). double mrs_lib::geometry::dist | ( | const vec2_t & | a, |
const vec2_t & | b | ||
) |
distnace between two 2D Eigen vectors
a | |
b |
double mrs_lib::geometry::dist | ( | const vec3_t & | a, |
const vec3_t & | b | ||
) |
distnace between two 3D Eigen vectors
a | |
b |
double mrs_lib::geometry::haversin | ( | const double | angle | ) |
computes the haversine (half of versine) for a given angle
angle | angle in radians |
double mrs_lib::geometry::headingFromRot | ( | const T & | rot | ) |
Returns the heading angle from the rotation.
Heading is defined as the angle of a [1,0,0] vector rotated by the rotation and projected to the XY plane from the X axis.
rot | the rotation to extract the heading angle from. |
double mrs_lib::geometry::invHaversin | ( | const double | value | ) |
computes the inverse haversine angle for a given value
value |
quat_t mrs_lib::geometry::quaternionBetween | ( | const vec3_t & | a, |
const vec3_t & | b, | ||
const double | tolerance = 1e-9 |
||
) |
Returns the rotation between two vectors, represented as a quaternion.
Works the same as the angleaxisBetween() function (in fact it is used in the implementation).
a | vector from which the rotation starts. |
b | vector at which the rotation ends. |
a
to b
. quat_t mrs_lib::geometry::quaternionFromEuler | ( | const Eigen::Vector3d & | euler | ) |
create a quaternion from Euler angles provided as a vector
euler | components of the rotation provided as vector of Euler angles |
quat_t mrs_lib::geometry::quaternionFromEuler | ( | double | x, |
double | y, | ||
double | z | ||
) |
create a quaternion from 3 provided Euler angles
x | Euler angle in radians |
y | Euler angle in radians |
z | Euler angle in radians |
quat_t mrs_lib::geometry::quaternionFromHeading | ( | const double | heading | ) |
create a quaternion from heading
Heading is defined as the angle of a [1,0,0] vector rotated by the rotation and projected to the XY plane from the X axis.
heading | the heading angle. |
mat3_t mrs_lib::geometry::rotateCovariance | ( | const mat3_t & | cov, |
const T & | rot | ||
) |
Returns the covariance rotated using the specified rotation.
cov | the covariance to be rotated. |
rot | the rotation use. |
Eigen::Matrix3d mrs_lib::geometry::rotationBetween | ( | const vec3_t & | a, |
const vec3_t & | b, | ||
const double | tolerance = 1e-9 |
||
) |
Returns the rotation between two vectors, represented as a rotation matrix.
Works the same as the angleaxisBetween() function (in fact it is used in the implementation).
a | vector from which the rotation starts. |
b | vector at which the rotation ends. |
a
to b
. double mrs_lib::geometry::solidAngle | ( | double | a, |
double | b, | ||
double | c | ||
) |
computes the solid angle for a spherical surface corresponding to a 'triangle' with edge lengths a, b, c
a | |
b | |
c |
double mrs_lib::geometry::sphericalTriangleArea | ( | Eigen::Vector3d | a, |
Eigen::Vector3d | b, | ||
Eigen::Vector3d | c | ||
) |
compute the area of a 'triangle' drawn on a spherical surface
a | length of side1 |
b | length of side2 |
c | length of side3 |
double mrs_lib::geometry::triangleArea | ( | const double | a, |
const double | b, | ||
const double | c | ||
) |
uses Heron's formula to compute area of a given triangle using side lengths
a | length of side1 |
b | length of side2 |
c | length of side3 |