Namespace inertialsim::geometry¶
Namespace List > inertialsim > geometry
Coordinates, rotations, rigid transforms, and geometric utilities. More...
Namespaces¶
| Type | Name |
|---|---|
| namespace | axis_angle Axis-angle rotation representation conversions (internal API). |
| namespace | cartesian Conversions to cartesian coordinates (internal API). |
| namespace | euler_angles Euler angle rotation representation conversions (internal API). |
| namespace | legendre Associated Legendre polynomials (internal API). |
| namespace | matrix Rotation matrix representation conversions (internal API). |
| namespace | power_series Power series approximations for common functions (internal API). |
| namespace | quaternion Quaternion rotation representation conversions (internal API). |
| namespace | random Random rotation generation utilities (internal API). |
| namespace | rotation_vector Rotation vector representation conversions (internal API). |
| namespace | spherical Conversions to spherical coordinates (internal API). |
Classes¶
| Type | Name |
|---|---|
| class | CoordinateRotation 3-dimensional coordinate frame rotations (passive convention). |
| class | CoordinateTransform 3-dimensional coordinate frame transforms (passive convention). |
| class | CoordinateTranslation 3-dimensional coordinate frame translations (passive convention). |
| class | ExtendedPose Pose plus velocity. |
| class | FloatingPointTolerances Singleton class for managing floating point tolerance settings. |
| class | MatrixLieGroup <typename Derived, GroupDimension, AlgebraDimension> Abstract base class for matrix Lie groups. |
| class | Pose Rigid body pose (position and orientation). |
| class | RigidTransform 3-dimensional rigid body transforms, SE(3) . |
| class | RigidTransformBase <typename Derived> Base class for 3-dimensional rigid body transform types. |
| class | Rotation 3-dimensional rotations of rigid bodies, SO(3) . |
| class | RotationBase <typename Derived> Base class for 3-dimensional rotation types. |
| class | Translation 3-dimensional translations. |
| class | Vector 3-dimensional vectors. |
| class | VectorBase <typename Derived> Base class for 3-dimensional vector types. |
Public Types¶
| Type | Name |
|---|---|
| enum | Integrator Integration methods. |
| enum | Interpolator |
Public Attributes¶
| Type | Name |
|---|---|
| const std::map< char, int > | kAxisIndex Map from axis character ( X ,Y ,Z ) to index. |
| const std::map< char, Vector3D > | kCartesianBasis Map from axis character ( X ,Y ,Z ) to basis vector. |
| constexpr double | kDefaultFpTolerance = 100.0 \* std::numeric\_limits<[**double**](namespaceinertialsim.md#typedef-matrix)>[**::epsilon**](namespaceinertialsim.md#typedef-matrix)()Standard tolerance for floating point equivalence checks. |
| constexpr double | kMetersPerInternationalFoot = 0.3048Common unit conversions. |
| constexpr int | kNumCartesianAxes = 3Standard number of Cartesian axes ( 3 ). |
| constexpr double | kPi = 3.14159265358979323846Common value of pi. |
| const Vector3D | kXBasis Standard Cartesian basis [1, 0, 0] . |
| const Vector3D | kYBasis Standard Cartesian basis [0, 1, 0] . |
| const Vector3D | kZBasis Standard Cartesian basis [0, 0, 1] . |
Public Functions¶
| Type | Name |
|---|---|
| Vector3D | CrossProduct (const Vector3D & a, const Vector3D & b) Compute the column-wise cross product of 3D vectors. |
| Array | CumulativeIntegral (const Array & array, const Timestamps & time, Integrator method=Integrator::TRAPEZOID, const std::optional< Array > initial_value=std::nullopt) Compute column-wise cumulative integral of an array. |
| Array | CumulativeSum (const Array & array) Compute column-wise cumulative sum of an array. |
| double | Deg2Rad (double degrees) Converts degrees to radians (scalar version). |
| Array | Deg2Rad (const Array & degrees) Converts degrees to radians (array version). |
| Scalar1D | DotProduct (const Vector3D & a, const Vector3D & b) Compute the column-wise dot (inner) product of 3D vectors. |
| std::vector< Scalar1D > | FiniteDifferenceWeights (const Timestamps & time, int order, int accuracy) Compute finite difference weights. |
| bool | IsOrthonormal (const RotationMatrix & matrix, std::optional< double > orthogonal_threshold=std::nullopt, std::optional< double > normal_threshold=std::nullopt) Check if a 3x3 matrix is orthonormal. |
| BooleanArray | IsOrthonormal (const RotationMatrixArray & matrices, std::optional< double > orthogonal_threshold=std::nullopt, std::optional< double > normal_threshold=std::nullopt) Check if an array of 3x3 matrices are orthonormal. |
| bool | IsSorted (const Scalar1D & array) Checks if an array is sorted. |
| bool | IsStrictlySorted (const Scalar1D & array) Checks if an array is strictly sorted. |
| bool | IsUnit (double value) Check if input is close to one. |
| BooleanArray | IsUnit (const Array & array) Check if elements of an array are close to one. |
| bool | IsZero (double value) Check if input is close to zero. |
| BooleanArray | IsZero (const Array & array) Check if elements of an array are close to zero. |
| int | LeviCivita (int i, int j, int k) Levi-Civita symbol. |
| std::pair< Matrix, Scalar1D > | NormalizeVector (const Matrix & vectors) Normalize an array of vectors. |
| double | Rad2Deg (double radians) Converts radians to degrees (scalar version). |
| Array | Rad2Deg (const Array & radians) Converts radians to degrees (array version). |
| int | Sign (double value) Element-wise sign function. |
| RotationMatrix | SkewMatrix (const Eigen::Vector3d & vector) Create a skew-symmetric matrix from a single 3D vector. |
| RotationMatrixArray | SkewMatrix (const Vector3D & vector) Create skew-symmetric matrices from multiple 3D vectors. |
| std::vector< Array > | SlidingWindow (const Array & array, int window_size) Column-wise sliding windows over an array. |
| IntegerArray | VectorArgmax (const Matrix & vectors) Find the argmax for each vector in an array. |
| Array | WrapTo2Pi (const Array & angle) Wraps the input angles such that 0 <= angle < 2*pi . |
| Array | WrapToPi (const Array & angle) Wraps the input angles such that -pi < angle <= pi . |
Detailed Description¶
The geometry namespace provides:
- methods to convert and validate user supplied inputs (arrays, vectors, matrices)
- classes to represent and manipulate geometric quantities (vectors, translations, rotations, rigid transforms, poses, etc.) based on Lie group theory
- classes to represent passive coordinate transforms
Input conventions
All inputs are expected to be in SI units.
By inertialsim convention, rotations and translations represent an active transformation (they act to rotate and translate an object relative to a fixed coordinate system). This is a common source of bugs, particularly in rotation logic. Reference [02], Reference [05], and Reference [11] discuss active vs. passive transforms in greater detail.
Because these conventions cannot be automatically validated, users must be aware of them and manage inputs and outputs.
Open-source packages
This module is tested for consistency against the following open source packages:
-
SciPy Spatial Transforms module: https://docs.scipy.org/doc/scipy/reference/spatial.transform.html
-
DFKI-RIC pytransform3d package: https://dfki-ric.github.io/pytransform3d/index.html
Public Types Documentation¶
enum Integrator¶
Integration methods.
Numerical integration methods for sampled data:
- EULER: Forward integration using a single sample.
- TRAPEZOID: Trapezoidal rule using average of samples at start and end.
- RK4: Runge-Kutta 4th order algorithm using 3 samples (start, mid, end). Equivalent to Simpson's rule for sampled data.
enum Interpolator¶
Public Attributes Documentation¶
variable kAxisIndex¶
Map from axis character ( X ,Y ,Z ) to index.
variable kCartesianBasis¶
Map from axis character ( X ,Y ,Z ) to basis vector.
variable kDefaultFpTolerance¶
Standard tolerance for floating point equivalence checks.
Value: 100 * std::numeric_limits<double>:: epsilon()
variable kMetersPerInternationalFoot¶
Common unit conversions.
Conversion factor from international feet to meters.
Note
This is the international foot and not the U.S. survey foot. Some older inertial navigation references use the latter. As of 1/1/2023, NIST recommends avoiding any use of the survey foot. The value of the international foot is defined in Standard [01]. See: https://www.nist.gov/pml/us-surveyfoot
variable kNumCartesianAxes¶
Standard number of Cartesian axes ( 3 ).
variable kPi¶
Common value of pi.
variable kXBasis¶
Standard Cartesian basis [1, 0, 0] .
variable kYBasis¶
Standard Cartesian basis [0, 1, 0] .
variable kZBasis¶
Standard Cartesian basis [0, 0, 1] .
Public Functions Documentation¶
function CrossProduct¶
Compute the column-wise cross product of 3D vectors.
Computes the cross product \(a \times b\) for each pair of column vectors.
Parameters:
aFirst vector array (3xN).bSecond vector array (3xN).
Returns:
Cross product result \(a \times b\) (3xN).
function CumulativeIntegral¶
Compute column-wise cumulative integral of an array.
Array inertialsim::geometry::CumulativeIntegral (
const Array & array,
const Timestamps & time,
Integrator method=Integrator::TRAPEZOID,
const std::optional< Array > initial_value=std::nullopt
)
Computes the cumulative integral of the input array over time using the specified integration method. Each row (axis) is integrated independently across columns (time samples).
Parameters:
arrayThe array to integrate (MxN where rows are independent axes, columns are time samples).timeThe time array (1xN).methodIntegration method (default: TRAPEZOID).initial_valueOptional initial value (Mx1) for the integral (defaults to zeros if not provided).
Returns:
The cumulative integral (same dimensions as input).
function CumulativeSum¶
Compute column-wise cumulative sum of an array.
Computes the cumulative sum of the input array. Each row (axis) is summed independently along columns (time samples).
Parameters:
arrayThe array to sum (MxN where rows are independent axes, columns are time samples).
Returns:
The cumulative sum (same dimensions as input).
function Deg2Rad¶
Converts degrees to radians (scalar version).
Parameters:
degreesAngle in degrees.
Returns:
Angle in radians.
function Deg2Rad¶
Converts degrees to radians (array version).
Parameters:
degreesAngle(s) in degrees.
Returns:
Angle(s) in radians.
function DotProduct¶
Compute the column-wise dot (inner) product of 3D vectors.
Computes the dot product \(a \cdot b\) for each pair of column vectors.
Parameters:
aFirst vector array (3xN).bSecond vector array (3xN).
Returns:
Dot product result \(a \cdot b\) (1xN).
function FiniteDifferenceWeights¶
Compute finite difference weights.
std::vector< Scalar1D > inertialsim::geometry::FiniteDifferenceWeights (
const Timestamps & time,
int order,
int accuracy
)
Calculates the weights for a Fornberg-style finite difference approximation of a function sampled at the input times. The order input defines the difference order (e.g., 1 for first derivative, 2 for second derivative). The accuracy input defines the approximation order of the result and should be a positive even integer (2, 4, 6, etc.). An accuracy of n requires n+1 neighboring samples.
If there are fewer samples than required for the requested accuracy, the accuracy will be reduced to the maximum possible. Central points will use a central difference scheme while edge points will use a full or partial forward or backward scheme with the requested accuracy.
See Reference [34] for details.
Parameters:
timeSample times.orderOrder of the finite difference approximation (0, 1, 2, ...).accuracyAccuracy of the finite difference approximation (positive even integer: 2, 4, 6, ...).
Returns:
Finite difference weights for each timestamp.
Exception:
std::invalid_argumentiforder< 0 or insufficient samples.
function IsOrthonormal¶
Check if a 3x3 matrix is orthonormal.
bool inertialsim::geometry::IsOrthonormal (
const RotationMatrix & matrix,
std::optional< double > orthogonal_threshold=std::nullopt,
std::optional< double > normal_threshold=std::nullopt
)
A matrix is orthonormal if its columns (or rows) are orthogonal unit vectors. An orthonormal matrix has determinant = 1.0 and rows/columns are orthogonal to each other. This is equivalent to checking that \(M^T M = I\) and \(\det(M) = 1\) within specified tolerances. All rotation matrices are orthonormal.
Parameters:
matrixThe 3x3 matrix to check.orthogonal_thresholdThreshold for orthogonality check (nullopt uses default from FloatingPointTolerances singleton). Columns must be orthogonal within this tolerance.normal_thresholdThreshold for normality check (nullopt uses default from FloatingPointTolerances). Column norms must be 1.0 within this tolerance.
Returns:
True if the matrix is orthonormal within the specified thresholds.
function IsOrthonormal¶
Check if an array of 3x3 matrices are orthonormal.
BooleanArray inertialsim::geometry::IsOrthonormal (
const RotationMatrixArray & matrices,
std::optional< double > orthogonal_threshold=std::nullopt,
std::optional< double > normal_threshold=std::nullopt
)
A matrix is orthonormal if its columns (or rows) are orthogonal unit vectors. An orthonormal matrix has determinant = 1.0 and rows/columns are orthogonal to each other. This is equivalent to checking that \(M^T M = I\) and \(\det(M) = 1\) within specified tolerances. All rotation matrices are orthonormal.
Parameters:
matricesVector of 3x3 matrices to check.orthogonal_thresholdThreshold for orthogonality check (nullopt uses default from FloatingPointTolerances singleton). Columns must be orthogonal within this tolerance.normal_thresholdThreshold for normality check (nullopt uses default from FloatingPointTolerances). Column norms must be 1.0 within this tolerance.
Returns:
Boolean array indicating orthonormality of each matrix.
function IsSorted¶
Checks if an array is sorted.
Checks if the input array is sorted in non-decreasing order. Duplicates are permitted. See IsStrictlySorted() to exclude duplicates.
Parameters:
arrayScalar array of values (1xN).
Returns:
True if sorted (allowing duplicates), false otherwise.
function IsStrictlySorted¶
Checks if an array is strictly sorted.
Checks if the input array is sorted in strictly increasing order. Duplicates are not permitted. See IsSorted() to include duplicates.
Example
Parameters:
arrayScalar array of values (1xN).
Returns:
True if strictly sorted (no duplicates), false otherwise.
function IsUnit¶
Check if input is close to one.
Checks if the value is close to one. The global tolerance currently set in the FloatingPointTolerances singleton is used for the comparison.
Parameters:
valueThe value to check.
Returns:
True if the value is "close" to one.
function IsUnit¶
Check if elements of an array are close to one.
Checks if the elements of the array are close to one. The global tolerance currently set in the FloatingPointTolerances singleton is used for the comparison.
Parameters:
arrayThe array to check.
Returns:
Elements close to one (boolean array).
function IsZero¶
Check if input is close to zero.
Checks if the value is close to zero. The global tolerance currently set in the FloatingPointTolerances singleton is used for the comparison.
The primary purpose of this function is to avoid numerical precision issues in expressions with small divisors. For example: mathematically sin(0.5x)/x has a well-behaved limit and tends to 0.5 as x tends to 0. However, this expression experiences numerical issues when x is extremely small.
Parameters:
valueThe value to check.
Returns:
True if the value is "close" to zero within tolerance.
function IsZero¶
Check if elements of an array are close to zero.
Checks if the elements of the array are close to zero. The global tolerance currently set in the FloatingPointTolerances singleton is used for the comparison.
Parameters:
arrayThe array to check.
Returns:
Elements close to zero (boolean array).
function LeviCivita¶
Levi-Civita symbol.
The Levi-Civita symbol is defined as:
- +1 if the sequence is an even permutation of (0,1,2) (cyclical)
- -1 if the sequence is an odd permutation of (0,1,2) (anti-cyclical)
- 0 otherwise (if any two indices are equal)
Parameters:
iFirst index in 3-dimensional sequence (must be 0, 1, or 2).jSecond index in 3-dimensional sequence (must be 0, 1, or 2).kThird index in 3-dimensional sequence (must be 0, 1, or 2).
Returns:
+1 for even permutations, -1 for odd permutations, 0 otherwise.
Exception:
std::invalid_argumentif any index is not in {0, 1, 2}.
function NormalizeVector¶
Normalize an array of vectors.
Normalizes vectors to unit length: u = v / norm(v), so that norm(u) = 1. Handles divide-by-zero gracefully by detecting zero-length vectors and returning them unchanged. The length (norm) of each vector is also returned.
Parameters:
vectorsMatrix where each column is a vector to normalize (MxN).
Returns:
Pair containing:
- Unit vectors (same dimensions as input)
- Array of norms corresponding to each unit vector (1xN)
function Rad2Deg¶
Converts radians to degrees (scalar version).
Parameters:
radiansAngle in radians.
Returns:
Angle in degrees.
function Rad2Deg¶
Converts radians to degrees (array version).
Parameters:
radiansAngle(s) in radians.
Returns:
Angle(s) in degrees.
function Sign¶
Element-wise sign function.
Unlike the standard sign function, 0 is treated as positive (+1).
Example
For input [-2, -1, 0, 1, 2], returns [-1, -1, 1, 1, 1]
Parameters:
valueThe input value.
Returns:
+1 if value >= 0, -1 if value < 0.
function SkewMatrix¶
Create a skew-symmetric matrix from a single 3D vector.
Returns the skew-symmetric matrix equivalent to the input vector. This matrix is also known as the cross product matrix or anti-symmetric matrix. It is the matrix equivalent of the cross product operator such that: \(a = b \times c\) is equivalent to \(a = [b]_{\times} c\), where \([b]_{\times}\) is the skew-symmetric matrix.
Parameters:
vectorA 3D vector.
Returns:
The 3x3 skew-symmetric (anti-symmetric) matrix.
function SkewMatrix¶
Create skew-symmetric matrices from multiple 3D vectors.
Returns the skew-symmetric matrix equivalent to each input vector. This matrix is also known as the cross product matrix or anti-symmetric matrix. It is the matrix equivalent of the cross product operator such that: \(a = b \times c\) is equivalent to \(a = [b]_{\times} c\), where \([b]_{\times}\) is the skew-symmetric matrix.
Parameters:
vectorsMatrix where each column is a 3D vector (3xN).
Returns:
Array of 3x3 skew-symmetric (anti-symmetric) matrices (one per input vector).
function SlidingWindow¶
Column-wise sliding windows over an array.
Creates an array of sliding windows (column-wise) over the input. window_size must be a positive integer.
The resulting view is centered on each input element. For edge points where the view cannot be centered, it returns the first window_size elements or the last window_size elements. For even window_size, the window is biased left of the input point.
The purpose of this function is to support windowed algorithms like interpolation and numerical differentiation.
Parameters:
arrayThe input array.window_sizeSize of each window (must be positive and <= array size).
Returns:
Vector of windowed arrays.
Exception:
std::invalid_argumentifwindow_size> array size orwindow_size< 1.
function VectorArgmax¶
Find the argmax for each vector in an array.
For each column vector, finds the index of the maximum component (0 <= index < M for Mx1 vectors). In the case of multiple occurrences of the same value, returns the index of the first occurrence.
Example
For vector [[0.1], [0.5], [0.3]], returns 1 (the row index of 0.5).
Parameters:
vectorsMatrix where each column is a vector (MxN).
Returns:
Indices of the maximum component of each column (1xN).
function WrapTo2Pi¶
Wraps the input angles such that 0 <= angle < 2*pi .
Parameters:
angleArray of angles. The operation is element-wise.
Returns:
Array of angles wrapped between [0, 2*pi).
function WrapToPi¶
Wraps the input angles such that -pi < angle <= pi .
Parameters:
angleArray of angles. The operation is element-wise.
Returns:
Array of angles wrapped between (-pi, pi].
The documentation for this class was generated from the following file cpp/include/inertialsim/geometry/angle.h