Wrong Unit? Zero Points!¶
wuzp is a header-only C++20 library that adds compile-time checks to the linear algebra libraries Eigen and Blitz++:
- Units. A force cannot be initialized with a mass, only with a mass times an acceleration, and every element of a matrix has its own unit, so heterogeneous matrices such as a mass matrix with
kgandkg m^2entries are checked too. - Coordinate systems. Every tensor is expressed in a coordinate system, a type without runtime cost: adding a force expressed in
Ato a force expressed inBdoes not compile, until a transformation expresses one in the coordinate system of the other. - Points and vectors. Points follow the rules of affine spaces:
p - qis a vector,p + va point, and operations whose result depends on the origin, e.g.p + qor2 * p, do not compile. - Index variance. Tensors know whether each index is upper (a vector) or lower (a covector), so only contractions of an upper with a lower index compile, and a covector is not mistaken for a vector.
- Transformations. Rotations, translations and proper rigid transformations, active and passive, Lorentz transformations and Jacobians, which compose with
*in the order of Drake's monogram notation and have aninverse(). - Spatial vectors. Spatial velocities, accelerations and forces (twists and wrenches) also know the frame a motion is measured in and the point it is about, like Drake's: the velocities of two different points cannot be added, until one is shifted to the other point.
All checks happen at compile time: with Eigen, wuzp is as fast as plain Eigen (see the benchmarks).
#include <wuzp/wuzp.hpp>
#include <wuzp_eigen/ValueMatrix.hpp>
#include <wuzp_units/Unit.hpp>
struct A {};
struct B {};
using CoordinateSystemA = wuzp::CoordinateSystem<A>;
using CoordinateSystemB = wuzp::CoordinateSystem<B>;
using ForceInA = wuzp::ForceVector3<wuzp_eigen::ValueMatrix, double, CoordinateSystemA>;
using ForceInB = wuzp::ForceVector3<wuzp_eigen::ValueMatrix, double, CoordinateSystemB>;
using RotationFromAToB = wuzp::PassiveSpatialRotation3<wuzp_eigen::ValueMatrix, double, CoordinateSystemA, CoordinateSystemB>;
int main() {
const ForceInA forceInA{1.0, 2.0, 3.0};
const ForceInB forceInB{4.0, 5.0, 6.0};
const RotationFromAToB rotation{1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0}; // B is A rotated by pi/2 around x.
// const ForceInB sum = forceInA + forceInB; // Error: Coordinate systems do not match.
const ForceInB sum = rotation.transform(forceInA) + forceInB;
return 0;
}
Where to go next¶
- Quickstart: add wuzp to a CMake project and compile a first program.
- Concepts: units and quantities, points and vectors, coordinate systems and metrics, tensors and index variance, transformations, and spatial vectors.
- Backends: the units and linear algebra libraries wuzp works with, and how to choose one.
- Cookbook: worked examples from rigid body kinematics and Lagrangian mechanics.
- Conventions: the transformation rules, the index placement and the notation, with their sources.
- Comparison with mp-units and Boost.Units, class hierarchy, limitations, and the API reference.
The design notes record why wuzp works the way it does, with the sources of its conventions and the results of a review of its mathematical and physical soundness.