Skip to content

raisim ​

namespace

The RaiSim physics engine: worlds, objects, articulated systems, contacts, sensors and the visualization server.

Namespaces ​

Classes ​

Core

  • class AlignedAllocator — Standard allocator that returns memory aligned to RSALOCATOR_ALIGNMENT bytes (e.g. for vectors of fixed-size Eigen-backed types).
  • struct CoacdOptions — CoACD convex decomposition parameters for mesh collision approximation.
  • struct ColorRGB — 8-bit RGB color (components 0-255).
  • struct ColorRGBA — 8-bit RGBA color (components 0-255).
  • class DynamicArray — Owning heap buffer of doubles; the common base of VecDyn and MatDyn.
  • class MatDyn — Dynamically sized matrix of doubles, stored column-major: element (i, j) is v[i + j * rows()].
  • class MaterialManager — Table of contact properties per material pair.
  • struct MaterialPairProperties — Contact properties of a pair of materials.
  • class noiseUtils — Internal: numeric helpers of the terrain noise generator.
  • class Path — A file system path string using the platform separator.
  • class PerlinNoise — 3D Perlin gradient noise with a seeded 256-entry permutation table (period 256 on each axis).
  • class RaiSimMsg — Message printer behind the RSINFO / RSWARN / RSFATAL macros (raisim_message.hpp).
  • class RaisimServer — Streams a raisim::World (plus server-side visual-only objects and charts) over TCP to a visualizer such as the rayrai TCP viewer, and accepts interaction / sim-control requests (pause, step,…
  • class RaiSimTinyXmlWrapper — Read-only convenience wrapper around a TinyXML element, used by the RaiSim XML, URDF and MJCF loaders.
  • class RaiSimTinyXmlWriter — Minimal XML document writer: add top-level elements with operator[] and write the file with saveFile().
  • class RaiSimTinyXmlWriterElement — Builder for one element of an XML document written by RaiSimTinyXmlWriter (used by World::exportToXml()).
  • struct Rasset — A reusable visual asset with collision shapes in the visual's local frame. .rasset files are XML; paths are relative to the descriptor, not the process.
  • class RayCollisionItem — One ray hit returned by World::rayTest().
  • class RayCollisionList — Hit list returned by World::rayTest().
  • class ScopedRaiSimFatalCallback — Restore-on-destruction wrapper for the calling thread's fatal callback.
  • class SparseJacobian — Sparse Jacobian with three rows (e.g. of a point's position or of a body's angular velocity with respect to the generalized velocity) that stores only its non-zero columns.
  • class SparseJacobian1D — Single-row counterpart of SparseJacobian: v holds the non-zero entries as a 1 x size row and entry i is column idx[i] of the full 1 x dof Jacobian.
  • class StopWatch — Wall-clock timer based on std::chrono::steady_clock.
  • class TerrainGenerator — Generates fractal Perlin-noise height samples from TerrainProperties.
  • struct TerrainProperties — Parameters of a fractal Perlin-noise terrain (see TerrainGenerator and World::addHeightMap()).
  • class TimedLoop — Scope guard for fixed-rate loops: its destructor sleeps until loopTimeInUs after its construction.
  • struct Transformation — Rigid transformation stored as a rotation matrix and a translation.
  • class VecDyn — Dynamically sized column vector of doubles (heap storage, see DynamicArray).
  • class World — The simulation world.

Objects

  • class Box — A rigid box.
  • class Capsule — A rigid capsule (a cylinder capped by two hemispheres) whose axis is the body z axis.
  • class Compound — A rigid body composed of primitive children (BOX, CYLINDER, CAPSULE, SPHERE) with user-given mass properties.
  • class Cone — A cone. Not supported by the current collision engine: the constructor raises a fatal error.
  • class Cylinder — A rigid cylinder whose axis is the body z axis.
  • class Mesh — A rigid body defined by a triangle mesh (create it with World::addMesh()).
  • class Object — Abstract base class of everything that can be added to a raisim::World: single bodies, terrains, articulated systems, deformable objects and granular systems.
  • class SingleBodyObject — Base class of rigid single-body objects (Sphere, Box, Cylinder, Capsule, Mesh, Compound, Ground, ...).
  • class Sphere — A rigid sphere.

Articulated systems

  • struct ActuatorCoupling — A coupling of an actuator's motor to a joint other than the one the actuator drives (see ActuatorDefinition).
  • struct ActuatorDefinition — An actuator: a DC/BLDC motor with its gear.
  • struct ActuatorState — The state of an actuator in the last simulation step, with the motor quantities on the motor (rotor) side of its gear.
  • class ArticulatedSystem — A tree of rigid bodies connected by joints (robot), simulated in generalized coordinates.
  • class ArticulatedSystemOption — Options passed to the ArticulatedSystem constructors.
  • class Body — Inertial, collision and visual properties of a link, used to build an articulated system (see Child).
  • class Child — Node of a kinematic tree (a body plus the joint connecting it to its parent), used to build an ArticulatedSystem programmatically.
  • struct CollisionBody — Collision geometry description of a Body, used when building an articulated system (see Body::addCollisionObject()).
  • struct CollisionDefinition — collision definition that is stored in Articulated System (see ArticulatedSystem::getCollisionBodies()).
  • class CoordinateFrame — A coordinate frame of an articulated system, defined at every joint (including fixed joints) and at sensors.
  • struct DcMotorParameters — Steady-state electrical model of the DC/BLDC motor inside an actuator, on the motor (rotor) side of the actuator's gear, in SI units.
  • class Joint — Joint connecting a body to its parent; used to build an articulated system (see Child).
  • struct MotorTorqueBounds — admissible motor torque interval at a given motor speed
  • struct Track — A rigid track (continuous belt) of an articulated system, defined by a URDF <track> element.
  • struct TrackDefinition — Internal: a <track> as read by the URDF loader, with its belt geometry already added to the link.
  • struct TrackDrive — A joint that moves the belt of a track: it adds gain * (joint velocity) to the belt speed.
  • struct VisObject — visualization definition created by a user or URDF

Terrain

  • class DeformableTerrain — A triangulated soil surface with no particles or soil inertia.
  • class Ground — A static infinite ground plane (half-space) with normal +z. Create it with World::addGround().
  • class HeightMap — A static terrain defined by a regular grid of heights (create it with World::addHeightMap()).

Deformable objects

  • class DeformableObject — A position-based (XPBD/PBD) deformable body made of particles connected by distance constraints (mesh edges plus optional extra edges) and, for cloth, bending constraints between adjacent triangles.

Granular media

  • class GranularPoolSleepController — Opt-in approximation for a settled pool.
  • class GranularSystem — A discrete-element (DEM) system of spherical particles stepped as one object (create it with World::addGranularParticles() or World::addGranularBox()).

Constraints and tendons

  • class CompliantLengthConstraint — A length constraint that acts as a linear spring (created by World::addCompliantWire()).
  • class Constraints — Base class of world-level constraints (see LengthConstraint). Holds the name, visualization color and a mutex.
  • class CustomLengthConstraint — A length constraint that applies a user-specified tension (see setTension(); created by World::addCustomWire()).
  • struct EqualityConstraintDefinition — Description of an equality constraint inside an articulated system, as parsed from URDF.
  • class LengthConstraint — Base class of the legacy distance constraints ("wires") between two points on two objects.
  • struct MimicConstraint — Internal: a resolved mimic constraint between two one-degree-of-freedom joints.
  • struct MimicConstraintDefinition — Description of a mimic constraint, as parsed from URDF (<mimic>) or MJCF (<equality><joint>): the follower joint's position is kept at multiplier * (leader position) + offset.
  • class PinConstraint — Internal: a resolved point constraint between two bodies of one articulated system.
  • struct PinConstraintDefinition — Description of a pin (point-to-point) constraint inside an articulated system, as parsed from URDF/MJCF.
  • class StiffLengthConstraint — A length constraint enforced as a hard limit (created by World::addStiffWire()).
  • class Tendon — A scalar transmission: routed spatial length or a weighted sum of scalar joints.
  • class TendonCoupling — Constrains the length of one tendon to a polynomial of another tendon's length.

Contact and collision

  • struct CollisionBodyHandle — Internal: per-body collision data registered with the contact engine (shape, owner, material).
  • class Contact — A contact point between two collision bodies, as stored in Object::getContacts().

Sensors

  • struct CameraFisheyeDistortion — OpenCV-fisheye (Kannala-Brandt) distortion coefficients k1..k4.
  • struct CameraIntrinsics — Pinhole-style camera intrinsics in pixels.
  • struct CameraLensModel — Lens description of a camera sensor: projection model, intrinsics and fisheye distortion.
  • class DepthCamera — Depth camera simulated by CPU ray casting against the collision geometry of the world.
  • class InertialMeasurementUnit — An ideal or stochastic six-axis IMU.
  • class RGBCamera — Color camera sensor.
  • class Sensor — Base class of all sensors attached to an ArticulatedSystem frame (RGBCamera, DepthCamera, InertialMeasurementUnit, SpinningLidar).
  • class SensorSet — A named group of sensors that belongs to one body of an ArticulatedSystem (e.g., all sensors of one physical device).
  • class SpinningLidar — Spinning (rotating-head) lidar simulated by CPU ray casting.

Server and visuals

  • struct ArticulatedSystemVisual — Visual-only articulated system (no physics) streamed by RaisimServer.
  • class BarChart — Bar chart (histogram) with one bar per named category.
  • class Chart — Base class of the charts streamed by RaisimServer (TimeSeriesGraph, BarChart).
  • struct HeightMapVisual — Visual-only height map (no physics) streamed by RaisimServer.
  • struct InstancedVisuals — Many visual-only instances of one shape, drawn with per-instance pose, scale and a color interpolated between color1 and color2.
  • struct PointCloud — Point cloud streamed by RaisimServer.
  • struct PolyLine — Visual-only polyline streamed by RaisimServer.
  • class TimeSeriesGraph — Line chart of one or more named series over time.
  • struct VisualMesh — Visual mesh created by RaisimServer::addVisualMesh(), either from a file or from raw arrays.
  • struct Visuals — Visual-only primitive (sphere, box, cylinder, capsule, arrow or mesh) streamed by RaisimServer.

Math

  • class BlockRef — Fixed-size n x m block view of a matrix, returned by Mat::segment(), Mat::head(), Mat::tail(), Mat::block() and the corner accessors.
  • class ColRef — View of one column (n elements) of a matrix, returned by Mat::col().
  • class CrossProduct — Lazy 3D cross product u x v of two 3x1 expressions, returned by cross() on a 3D vector.
  • class DiagonalRef — Placeholder proxy for a matrix diagonal. It has no accessors and no Mat method returns it.
  • class Div_SL_op — Lazy scalar / matrix element-wise expression (Div_SL_op), returned by operator/(double, MatExpr).
  • class ElementRef — Proxy returned by the comma initializers (Mat::operator<<() and DynamicArray::operator=(double)); each following , value writes the next element in linear (column-major) order.
  • class Mat — Fixed-size n x m matrix of doubles, stored column-major: element (i, j) is v[i + j * n].
  • class MatExpr — CRTP base of all fixed-size matrix types and expression templates (Mat, the block views and the lazy arithmetic expressions).
  • class Prod_op — Lazy matrix-product expression returned by operator* on two fixed-size matrix expressions.
  • class Prod_op< Mat< 4, 4 >, Mat< 4, 4 > > — Specialization for the 4x4 by 4x4 product: it is evaluated eagerly (with Eigen) when constructed and stores the result.
  • class RowRef — View of one row (m elements) of a matrix, returned by Mat::row().
  • class SkewRef — Proxy returned by skew() on a 3D vector.
  • class Sub_SL_op — Lazy scalar - matrix expression (Sub_SL_op), returned by operator-(double, MatExpr).
  • class Transpose — Lazy expression for the transpose of a fixed-size matrix expression, returned by Mat::transpose().

Enumerations ​

ObjectType ​

#include <raisim/configure.hpp>

cpp
enum ObjectType : int

Object type identifiers.

EnumeratorValue
SPHERE0
BOX
CYLINDER
CONE
CAPSULE
MESH
HALFSPACE
COMPOUND
HEIGHTMAP
ARTICULATED_SYSTEM
DEFORMABLE
GRANULAR
UNRECOGNIZED

MeshCollisionMode ​

#include <raisim/configure.hpp>

cpp
enum class MeshCollisionMode : int

Mesh collision handling modes.

EnumeratorValueDescription
ORIGINAL_MESH0keep the (possibly non-convex) triangle mesh
CONVEX_HULLuse one convex hull of the mesh
CONVEXIFYCoACD convex decomposition (see CoacdOptions).

BodyType ​

#include <raisim/configure.hpp>

cpp
enum class BodyType : int

Body type identifiers.

EnumeratorValueDescription
STATIC1not movable, infinite mass
KINEMATIC2moves with its set velocity, infinite mass; ignores forces, gravity and contacts
DYNAMIC3movable, finite mass

MotorSaturation ​

#include <raisim/object/ArticulatedSystem/MotorOperatingRegion.hpp>

cpp
enum class MotorSaturation : int

The bound of the operating region that limits a motor torque.

EnumeratorValueDescription
NONE0the torque is inside the operating region
PEAK_TORQUE1the torque is limited by the peak torque
VOLTAGE2the torque is limited by the bus voltage (back EMF)

GyroscopicMode ​

#include <raisim/object/singleBodies/SingleBodyObject.hpp>

cpp
enum GyroscopicMode

How single bodies integrate the gyroscopic term w x (I w). The default is IMPLICIT_GYROSCOPIC_FORCE_BODY (Sphere uses EXPLICIT_GYROSCOPIC_FORCE).

EnumeratorDescription
IMPLICIT_GYROSCOPIC_FORCE_BODYImplicit integration in the body frame (stable, more computation).
IMPLICIT_GYROSCOPIC_FORCE_WORLDLinearly implicit integration in the world frame (stable, more computation).
EXPLICIT_GYROSCOPIC_FORCEExplicit integration (can be unstable, less computation).
NO_GYROSCOPIC_FORCEThe gyroscopic term is ignored.

CameraProjectionType ​

#include <raisim/sensors/CameraLens.hpp>

cpp
enum class CameraProjectionType : int

Camera projection model used by RGBCamera and DepthCamera.

EnumeratorValueDescription
PINHOLE0Rectilinear (perspective) projection.
FISHEYE_EQUIDISTANT1Equidistant fisheye: image radius proportional to the ray angle (r = f * theta).

Type aliases ​

CollisionBodyHandlePtr ​

#include <raisim/collision/CollisionBody.hpp>

cpp
using CollisionBodyHandlePtr = CollisionBodyHandle *

CollisionBodyHandleConstPtr ​

#include <raisim/collision/CollisionBody.hpp>

cpp
using CollisionBodyHandleConstPtr = const CollisionBodyHandle *

CollisionGroup ​

#include <raisim/configure.hpp>

cpp
typedef uint64_t CollisionGroup

Collision group / mask bit set. Two bodies collide if each one's group intersects the other's mask.

Vec ​

#include <raisim/math.hpp>

cpp
template <size_t Size>
using Vec = Mat<Size, 1>

Fixed-size column vector of doubles; Vec<Size> is an alias of Mat<Size, 1>.

ScalarType ​

#include <raisim/math/Matrix.hpp>

cpp
using ScalarType = double

CollisionSet ​

#include <raisim/object/ArticulatedSystem/JointAndBodies.hpp>

cpp
typedef std::vector<CollisionDefinition> CollisionSet

Collision bodies of an articulated system.

Functions ​

strtodClassic ​

#include <raisim/ClassicNumber.hpp>

cpp
double strtodClassic(const char *text, char **end)

strtod() in the classic "C" locale, whatever locale the application set.

Parameters

ParameterDescription
text (in)the number's text
end (out)receives the first character after the number (text when there is none); may be null

Returns the value, setting errno as strtod() does

snprintfClassic ​

#include <raisim/ClassicNumber.hpp>

cpp
int snprintfClassic(char *buffer, std::size_t size, const char *format,...)

snprintf() in the classic "C" locale, whatever locale the application set.

Parameters

ParameterDescription
buffer (out)receives the text, always terminated when size > 0
size (in)its size
format (in)printf format

Returns the length of the whole text (which may not have fit), or a negative value on an error, as snprintf() returns

searchForFile ​

#include <raisim/Path.hpp>

cpp
static Path searchForFile(
    const std::string &filename,
    const Path &searchRoot,
    const std::vector<std::string> &hints)

Look for a file directly under a root directory, then under each hint subdirectory.

Parameters

ParameterDescription
filename (in)file name (or relative path) to find
searchRoot (in)directory to search
hints (in)subdirectories of searchRoot to try, in order

Returns the first existing searchRoot/filename or searchRoot/hint/filename, or Path("") if none exists

pathFromUtf8 ​

#include <raisim/PathUtils.hpp>

cpp
std::filesystem::path pathFromUtf8(const std::string &text)

Convert authored UTF-8 paths without relying on the Windows active code page.

pathUtf8 ​

#include <raisim/PathUtils.hpp>

cpp
std::string pathUtf8(const std::filesystem::path &path)

UTF-8 with generic separators, suitable for scene files and protocol messages.

validateTerrainProperties ​

#include <raisim/Terrain.hpp>

cpp
bool validateTerrainProperties(
    const TerrainProperties &properties,
    size_t minimumSamples,
    std::string *reason=nullptr)

Validate every property before terrain normalization, allocation, or noise sampling. The minimum sample count is one for a standalone TerrainGenerator and two for a HeightMap, whose interpolation requires one cell on each axis.

Parameters

ParameterDescription
properties (in)properties to check
minimumSamples (in)minimum sample count per axis
reason (out)if not nullptr, receives the reason of a failure

Returns true if the properties are valid

COLLISION ​

#include <raisim/World.hpp>

cpp
static CollisionGroup COLLISION(CollisionGroup group)

Parameters

ParameterDescription
group (in)Collision group ID

Returns Collision group. Can also be used as a collision mask.

materialChangeCounter ​

#include <raisim/collision/material_dirty.hpp>

cpp
std::uint64_t materialChangeCounter()

Returns Current material change counter value.

notifyMaterialChange ​

#include <raisim/collision/material_dirty.hpp>

cpp
void notifyMaterialChange()

Increment the material change counter to invalidate caches.

isSingleBody ​

#include <raisim/configure.hpp>

cpp
bool isSingleBody(ObjectType type)

Parameters

ParameterDescription
type (in)Object type.

Returns True if the type corresponds to a single-body object.

isMovableBody ​

#include <raisim/configure.hpp>

cpp
bool isMovableBody(ObjectType type)

Parameters

ParameterDescription
type (in)Object type.

Returns True if the type is movable (finite mass or articulated).

isMovableSingleBody ​

#include <raisim/configure.hpp>

cpp
bool isMovableSingleBody(ObjectType type)

Parameters

ParameterDescription
type (in)Object type.

Returns True if the type is a movable single body.

isSingleCollisionBody ​

#include <raisim/configure.hpp>

cpp
bool isSingleCollisionBody(ObjectType type)

Parameters

ParameterDescription
type (in)Object type.

Returns True if the type maps to a single collision body.

isPrimitiveCollisionBody ​

#include <raisim/configure.hpp>

cpp
bool isPrimitiveCollisionBody(ObjectType type)

Parameters

ParameterDescription
type (in)Object type.

Returns True if the type is a primitive collision shape.

isMustHaveInertiaDefined ​

#include <raisim/configure.hpp>

cpp
bool isMustHaveInertiaDefined(ObjectType type)

Parameters

ParameterDescription
type (in)Object type.

Returns True if inertia must be specified explicitly for the type.

stringToObjectType ​

#include <raisim/configure.hpp>

cpp
ObjectType stringToObjectType(const std::string &typeName)

Parameters

ParameterDescription
typeName (in)Object type string ("sphere", "box", "cylinder", "cone", "capsule", "mesh", "ground", "compound", "heightmap", "articulatedSystem"/"articulated_system", "deformable" or "granular").

Returns Parsed ObjectType value, or UNRECOGNIZED.

objectTypeToString ​

#include <raisim/configure.hpp>

cpp
std::string objectTypeToString(ObjectType type)

Inverse of stringToObjectType() (ARTICULATED_SYSTEM maps to "articulatedSystem").

Parameters

ParameterDescription
type (in)Object type.

Returns Lower-case type name, e.g. "sphere" or "ground" for HALFSPACE.

updateContactBodyTransform ​

#include <raisim/contact_engine/body_update.hpp>

cpp
void updateContactBodyTransform(
    ::contact::Body &body,
    const Vec<3> &position,
    const Mat<3, 3> &rotation)

Set the pose of a collision body and refresh its cached rotation data (and, for planes, the world-frame plane). The rotation is stored as a matrix; transform.rotation is reset to identity.

Parameters

ParameterDescription
body (in, out)Collision body.
position (in)World position.
rotation (in)World orientation (body-to-world rotation matrix).

buildContactMeshConvexHull ​

#include <raisim/contact_engine/contact_build.hpp>

cpp
std::shared_ptr<::contact::Mesh> buildContactMeshConvexHull(const std::vector<float> &vertices)

Build a convex collision mesh from the convex hull of a point set.

Parameters

ParameterDescription
vertices (in)Packed xyz coordinates.

Returns The hull mesh, or nullptr if no hull could be built.

validateContactMeshInput ​

#include <raisim/contact_engine/contact_build.hpp>

cpp
template <typename IndexT>
void validateContactMeshInput(
    const std::vector<float> &vertices,
    const std::vector<IndexT> &indices)

Fatal error unless vertices is packed xyz with finite values and indices are triangles with in-range vertex indices.

buildContactMesh ​

#include <raisim/contact_engine/contact_build.hpp>

cpp
template <typename IndexT>
std::shared_ptr<::contact::Mesh> buildContactMesh(
    const std::vector<float> &vertices,
    const std::vector<IndexT> &indices)

Build a collision mesh (with BVH and adjacency) from packed xyz vertices and triangle indices. Invalid input is a fatal error (see validateContactMeshInput()).

cpp
template <typename IndexT>
std::shared_ptr<::contact::Mesh> buildContactMesh(
    const std::vector<float> &vertices,
    const std::vector<IndexT> &indices,
    bool convexify)

Build a collision mesh, optionally convexified: with convexify the convex hull is used, falling back to the bounding box if the hull cannot be built.

buildContactMeshConvexAabb ​

#include <raisim/contact_engine/contact_build.hpp>

cpp
std::shared_ptr<::contact::Mesh> buildContactMeshConvexAabb(const std::vector<float> &vertices)

Returns A box-shaped collision mesh spanning the bounding box of the packed xyz vertices (a zero box if there are none).

buildContactHeightmap ​

#include <raisim/contact_engine/contact_build.hpp>

cpp
std::shared_ptr<::contact::Heightmap> buildContactHeightmap(const raisim::HeightMap &hm)

Returns The collision heightmap of a raisim::HeightMap (bounds and tiles built, no triangle mesh).

separator ​

#include <raisim/helper.hpp>

cpp
std::string separator()

Returns the platform path separator ("\\" on Windows, "/" elsewhere)

MSLEEP ​

#include <raisim/helper.hpp>

cpp
void MSLEEP(int sleepMs)

Sleep the calling thread. Non-positive values return immediately.

Parameters

ParameterDescription
sleepMs (in)duration (ms)

USLEEP ​

#include <raisim/helper.hpp>

cpp
void USLEEP(int sleepUs)

Sleep the calling thread. Non-positive values return immediately.

Parameters

ParameterDescription
sleepUs (in)duration (microseconds)

getBaseFileName ​

#include <raisim/helper.hpp>

cpp
std::string getBaseFileName(const std::string &fullPath)

Parameters

ParameterDescription
fullPath (in)file path

Returns the file name without directory and (last) extension

getTopDirectory ​

#include <raisim/helper.hpp>

cpp
std::string getTopDirectory(const std::string &fullPath)

Parameters

ParameterDescription
fullPath (in)file path

Returns the name of the directory that contains the file (e.g. "b" for "/a/b/c.txt")

getFileName ​

#include <raisim/helper.hpp>

cpp
std::string getFileName(const std::string &fullPath)

Parameters

ParameterDescription
fullPath (in)file path

Returns the file name including the extension

getFileExtension ​

#include <raisim/helper.hpp>

cpp
std::string getFileExtension(const std::string &fullPath)

Parameters

ParameterDescription
fullPath (in)file path

Returns the last file extension without the dot, or an empty string

getPathName ​

#include <raisim/helper.hpp>

cpp
std::string getPathName(const std::string &fullPath)

Parameters

ParameterDescription
fullPath (in)file path

Returns the full path containing the file (remove the file name in the full path)

fileExists ​

#include <raisim/helper.hpp>

cpp
bool fileExists(const std::string &name)

Parameters

ParameterDescription
name (in)file path

Returns true if a regular file exists at the path

directoryExists ​

#include <raisim/helper.hpp>

cpp
bool directoryExists(const std::string &name)

Parameters

ParameterDescription
name (in)directory path

Returns true if a directory exists at the path

read_png_file ​

#include <raisim/helper.hpp>

cpp
void read_png_file(
    const char *file_name,
    int &width,
    int &height,
    std::vector<double> &values,
    double scale,
    double zOffset)

Internal: reads an 8- or 16-bit grayscale PNG as height values (value = pixel * scale + zOffset). Values are stored row by row; within a row the columns are stored from right to left. Fatal for a missing file, a non-grayscale image or another bit depth.

Parameters

ParameterDescription
file_name (in)PNG file path
width (out)image width (pixels)
height (out)image height (pixels)
values (out)width * height values; cleared first
scale (in)scale applied to the raw pixel value
zOffset (in)offset added after scaling

operator, ​

#include <raisim/math.hpp>

cpp
template <int n>
ElementRef<DynamicArray> operator,(ElementRef<DynamicArray> ref, double a)
cpp
template <int n>
ElementRef<Vec<n>> operator,(ElementRef<Vec<n>> ref, double a)
cpp
template <int n, int m>
ElementRef<Mat<n, m>> operator,(ElementRef<Mat<n, m>> ref, double a)

operator<< ​

#include <raisim/math.hpp>

cpp
template <int n>
std::ostream &operator<<(std::ostream &os, const Vec<n> &m)

Prints the elements of a vector on one line, separated by spaces.

cpp
template <size_t n, size_t m>
std::ostream &operator<<(std::ostream &os, const Mat<n, m> &mat)

Prints a matrix row by row, one line per row.

cpp
std::ostream &operator<<(std::ostream &os, const VecDyn &m)

Prints the elements on one line, separated by spaces.

cpp
std::ostream &operator<<(std::ostream &os, const MatDyn &mat)

Prints a matrix row by row, one line per row.

cholInv ​

#include <raisim/math.hpp>

cpp
template <size_t n>
static bool cholInv(const double *A, double *AInv)

Inverts a symmetric positive-definite n x n matrix using a Cholesky factorization.

Parameters

ParameterDescription
A (in)input matrix, n*n doubles in column-major order
AInv (out)inverse of A (full symmetric matrix, column-major); must not overlap A

Returns false when a pivot of the factorization is at most 1e-12 of its diagonal entry: A is not positive definite, or singular to working precision (a NaN pivot does not count), and AInv is then meaningless

cholInv2 ​

#include <raisim/math.hpp>

cpp
template <size_t n>
static void cholInv2(const double *A, double *AInv)

Inverts a symmetric positive-definite n x n matrix using a Cholesky factorization (alternative implementation of cholInv()).

Parameters

ParameterDescription
A (in)input matrix, n*n doubles in column-major order
AInv (out)inverse of A (full symmetric matrix, column-major)

quatToRotMat ​

#include <raisim/math.hpp>

cpp
void quatToRotMat(const Vec<4> &q, Mat<3, 3> &R)

Converts a quaternion to a rotation matrix.

Parameters

ParameterDescription
q (in)quaternion in (w, x, y, z) order. It must be normalized; a non-unit q yields a matrix scaled by its squared norm.
R (out)rotation matrix. If q is the orientation of a body frame B in frame W, then v_W = R * v_B.
cpp
void quatToRotMat(const double *q, Mat<3, 3> &R)

Converts a quaternion given as a raw array to a rotation matrix; otherwise identical to the Vec<4> overload.

Parameters

ParameterDescription
q (in)four doubles in (w, x, y, z) order, normalized
R (out)rotation matrix

rotMatToQuat ​

#include <raisim/math.hpp>

cpp
void rotMatToQuat(const Mat<3, 3> &R, Vec<4> &q)

Converts a rotation matrix to a quaternion. Inverse of quatToRotMat().

Parameters

ParameterDescription
R (in)proper rotation matrix (orthonormal, determinant +1)
q (out)quaternion in (w, x, y, z) order. Its sign is not normalized: w is positive when the trace of R is positive and may be negative otherwise.

rpyToRotMat_intrinsic ​

#include <raisim/math.hpp>

cpp
void rpyToRotMat_intrinsic(const Vec<3> &rpy, Mat<3, 3> &R)

Converts roll-pitch-yaw angles to the rotation matrix R = Rz(yaw) * Ry(pitch) * Rx(roll).

Parameters

ParameterDescription
rpy (in)(roll, pitch, yaw) in radians
R (out)rotation matrix

rpyToRotMat_extrinsic ​

#include <raisim/math.hpp>

cpp
void rpyToRotMat_extrinsic(const Vec<3> &rpy, Mat<3, 3> &R)

Converts roll-pitch-yaw angles to the rotation matrix R = Rx(roll) * Ry(pitch) * Rz(yaw) (the reverse composition order of rpyToRotMat_intrinsic()).

Parameters

ParameterDescription
rpy (in)(roll, pitch, yaw) in radians
R (out)rotation matrix

angleAxisToRotMat ​

#include <raisim/math.hpp>

cpp
void angleAxisToRotMat(
    const Vec<3> &a1,
    const double theta,
    Mat<3, 3> &rotMat)

Rotation matrix of a rotation by theta about a1 (Rodrigues' formula).

Parameters

ParameterDescription
a1 (in)rotation axis; must be a unit vector (not normalized here)
theta (in)rotation angle in radians
rotMat (out)rotation matrix

angleAxisToQuaternion ​

#include <raisim/math.hpp>

cpp
void angleAxisToQuaternion(
    const Vec<3> &a1,
    const double theta,
    Vec<4> &quaternion)

Quaternion of a rotation by theta about a1.

Parameters

ParameterDescription
a1 (in)rotation axis; must be a unit vector (not normalized here)
theta (in)rotation angle in radians
quaternion (out)result in (w, x, y, z) order

quatMul ​

#include <raisim/math.hpp>

cpp
void quatMul(const Vec<4> &q, const Vec<4> &p, Vec<4> &pq)

Hamilton product of two quaternions in (w, x, y, z) order. Despite the output's name, the result is q * p (the rotation p followed by q).

Parameters

ParameterDescription
q (in)left factor
p (in)right factor
pq (out)the product q * p; must not alias q or p
cpp
void quatMul(const double *q, const double *p, double *pq)

Raw-array version of quatMul(): pq = q * p, (w, x, y, z) order; pq must not alias the inputs.

quatInvQuatMul ​

#include <raisim/math.hpp>

cpp
void quatInvQuatMul(const double *q, const double *p, double *pq)

Computes pq = conj(q) * p for quaternions in (w, x, y, z) order (q^-1 * p for a unit q); pq must not alias the inputs.

matvecAddDiagonally ​

#include <raisim/math.hpp>

cpp
void matvecAddDiagonally(MatDyn &mat, const VecDyn &diag)

Overwrites the diagonal of the square matrix mat with diag. Despite its name it does not add (see addToDiagonal() for that); off-diagonal entries are unchanged. The dimensions are checked only in debug builds.

eulerVecToQuat ​

#include <raisim/math.hpp>

cpp
void eulerVecToQuat(const Vec<3> &eulerVec, Vec<4> &quat)

Converts a rotation vector (unit axis times angle in radians) to a quaternion.

Parameters

ParameterDescription
eulerVec (in)rotation vector
quat (out)quaternion in (w, x, y, z) order; identity if |eulerVec| < 1e-12

quatToEulerVec ​

#include <raisim/math.hpp>

cpp
void quatToEulerVec(const double *quat, double *eulerVec)

Converts a unit quaternion to a rotation vector (unit axis times angle). The angle is 2 * acos(w) in [0, 2*pi]; a quaternion with negative w is not flipped, so the angle can exceed pi.

Parameters

ParameterDescription
quat (in)four doubles in (w, x, y, z) order
eulerVec (out)three doubles; zero if the norm of the quaternion's vector part is below 1e-12

matmul ​

#include <raisim/math.hpp>

cpp
void matmul(const Mat<3, 3> &mat1, const Mat<3, 3> &mat2, Mat<3, 3> &mat)

mat = mat1 * mat2. mat may alias mat1 or mat2.

cpp
void matmul(const Mat<4, 4> &mat1, const Mat<4, 4> &mat2, Mat<4, 4> &mat)

mat = mat1 * mat2. mat may alias mat1 or mat2.

cpp
template <size_t i, size_t j, size_t k>
void matmul(const Mat<i, j> &mat1, const Mat<j, k> &mat2, Mat<i, k> &mat)

mat = mat1 * mat2 for fixed-size matrices. mat may alias mat1 or mat2.

cpp
void matmul(const MatDyn &mat1, const MatDyn &mat2, MatDyn &mat)

mat = mat1 * mat2; mat is resized if needed and may alias mat1 or mat2.

cpp
void matmul(const MatDyn &mat1, const Mat<3, 3> &mat2, MatDyn &mat)

mat = mat1 * mat2 with mat1 of size rows x 3; mat is resized to rows x 3 if needed and may alias mat1.

cpp
void matmul(const Mat<3, 3> &mat1, const MatDyn &mat2, MatDyn &mat)

mat = mat1 * mat2 with mat2 of size 3 x cols; mat is resized to 3 x cols if needed and may alias mat2.

cpp
void matmul(const SparseJacobian &jaco, const VecDyn &vec, Vec<3> &result)

result = J * vec, where J is the full 3 x dof Jacobian represented by jaco.

Parameters

ParameterDescription
jaco (in)sparse Jacobian
vec (in)vector with dof elements, indexed by jaco.idx (e.g. the generalized velocity)
result (out)the 3D product

matmattransposemul ​

#include <raisim/math.hpp>

cpp
void matmattransposemul(
    const Mat<3, 3> &mat1,
    const Mat<3, 3> &mat2,
    Mat<3, 3> &mat)

mat = mat1 * mat2^T. mat must not alias the inputs.

mattransposematmul ​

#include <raisim/math.hpp>

cpp
void mattransposematmul(
    const Mat<3, 3> &mat1,
    const Mat<3, 3> &mat2,
    Mat<3, 3> &mat)

mat = mat1^T * mat2. mat must not alias the inputs.

rotmatmul ​

#include <raisim/math.hpp>

cpp
void rotmatmul(const Mat<3, 3> &mat1, const Mat<3, 3> &mat2, Mat<3, 3> &mat)

mat = mat1 * mat2 for rotation matrices. Only the first two columns are computed by multiplication; the third is their cross product, which keeps the result right-handed. mat must not alias the inputs.

matmul_fillBot3Rows ​

#include <raisim/math.hpp>

cpp
void matmul_fillBot3Rows(
    const Mat<3, 3> &mat1,
    const Mat<3, 3> &mat2,
    Mat<6, 3> &mat)

Writes mat1 * mat2 into rows 3 to 5 of mat; rows 0 to 2 are left untouched.

transposedMatMul ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m, size_t l>
void transposedMatMul(
    const Mat<m, n> &mat1,
    const Mat<m, l> &mat2,
    Mat<n, l> &mat)

mat = mat1^T * mat2 (the first matrix is transposed). mat must not alias the inputs.

transposed2MatMul ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m, size_t l>
void transposed2MatMul(
    const Mat<n, m> &mat1,
    const Mat<l, m> &mat2,
    Mat<n, l> &mat)

mat = mat1 * mat2^T (the second matrix is transposed). mat must not alias the inputs.

cpp
void transposed2MatMul(
    const MatDyn &mat1,
    const Mat<3, 3> &mat2,
    MatDyn &mat)

mat = mat1 * mat2^T with mat1 of size rows x 3. mat must already be rows x 3 (it is not resized) and must not alias mat1.

matScalarMul ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t l>
void matScalarMul(double scalar, Mat<n, l> &mat)

mat *= scalar.

cpp
template <size_t n, size_t l>
void matScalarMul(double scalar, const Mat<n, l> &mat1, Mat<n, l> &mat)

mat = scalar * mat1. Assigns; the destination's previous contents are irrelevant.

similarityTransform ​

#include <raisim/math.hpp>

cpp
void similarityTransform(
    const Mat<3, 3> &R,
    const Mat<3, 3> &I,
    Mat<3, 3> &mat)

mat = R * I * R^T, e.g. to rotate an inertia tensor. I must be symmetric; the result is written symmetric. mat must not alias R.

similarityTransform2 ​

#include <raisim/math.hpp>

cpp
void similarityTransform2(
    const Mat<3, 3> &R,
    const Mat<3, 3> &I,
    Mat<3, 3> &mat)

mat = R^T * I * R. I must be symmetric; the result is written symmetric. mat must not alias R.

transpose ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m>
void transpose(const Mat<n, m> &mat1, Mat<m, n> &mat)

mat = mat1^T. mat must not alias mat1.

matvecmul ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m>
void matvecmul(const Mat<n, m> &mat1, const Vec<m> &vec1, Vec<n> &vec)

vec = mat1 * vec1. vec may alias vec1 only for square matrices.

cpp
void matvecmul(const MatDyn &mat1, const VecDyn &vec1, VecDyn &vec)

vec = mat1 * vec1; vec is resized if needed and may alias vec1.

cpp
void matvecmul(const Mat<3, 3> &mat1, const Vec<3> &vec1, double *vec)

vec = mat1 * vec1, written to a 3-element array that must not alias vec1.

cpp
void matvecmul(const Mat<3, 3> &mat1, const Vec<3> &vec1, Vec<3> &vec)

vec = mat1 * vec1. vec may alias vec1.

matTransposevecmul ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m>
void matTransposevecmul(
    const Mat<n, m> &mat1,
    const Vec<n> &vec1,
    Vec<m> &vec)

vec = mat1^T * vec1. vec must not alias vec1.

cpp
void matTransposevecmul(const MatDyn &mat1, const VecDyn &vec1, VecDyn &vec)

vec = mat1^T * vec1; vec is resized if needed and may alias vec1.

matvecmulInvertSgn ​

#include <raisim/math.hpp>

cpp
void matvecmulInvertSgn(
    const Mat<3, 3> &mat1,
    const Vec<3> &vec1,
    Vec<3> &vec)

vec = -mat1 * vec1. vec must not alias vec1.

matvecmulThenAdd ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m>
void matvecmulThenAdd(
    const Mat<n, m> &mat1,
    const Vec<m> &vec1,
    Vec<n> &vec)

vec += mat1 * vec1. vec must not alias vec1.

cpp
void matvecmulThenAdd(
    const Mat<3, 3> &mat1,
    const Vec<3> &vec1,
    Vec<3> &vec)

vec += mat1 * vec1. vec must not alias vec1.

cpp
void matvecmulThenAdd(
    const Mat<3, 3> &mat1,
    const Vec<3> *vec1,
    Vec<3> &vec)

vec += mat1 * (*vec1). vec must not alias vec1.

cpp
void matvecmulThenAdd(const MatDyn &mat1, const Vec<3> &vec1, VecDyn &vec)

vec += mat1 * vec1 with mat1 of size rows x 3; vec must have at least mat1.rows() elements.

matvecmulThenSub ​

#include <raisim/math.hpp>

cpp
void matvecmulThenSub(const MatDyn &mat1, const Vec<3> &vec1, VecDyn &vec)

vec -= mat1 * vec1 with mat1 of size rows x 3; vec must have at least mat1.rows() elements.

cpp
template <size_t n, size_t m>
void matvecmulThenSub(
    const Mat<n, m> &mat1,
    const Vec<m> &vec1,
    Vec<n> &vec)

vec -= mat1 * vec1. vec must not alias vec1.

matTransposeVecmulThenAdd ​

#include <raisim/math.hpp>

cpp
template <size_t m>
void matTransposeVecmulThenAdd(
    const MatDyn &mat1,
    const Vec<m> &vec1,
    VecDyn &vec)

vec += mat1^T * vec1. mat1 must have exactly m rows (used as its leading dimension) and vec at least mat1.cols() elements.

cpp
template <size_t n, size_t m>
void matTransposeVecmulThenAdd(
    const Mat<n, m> &mat1,
    const Vec<n> &vec1,
    Vec<m> &vec)

vec += mat1^T * vec1. vec must not alias vec1.

vecsub ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecsub(const Vec<size> &vec1, const Vec<size> &vec2, Vec<size> &vec)

vec = vec1 - vec2.

cpp
void vecsub(const VecDyn &vec1, const VecDyn &vec2, VecDyn &vec)

vec = vec1 - vec2 over vec1.size() elements; vec must already have that size.

cpp
template <size_t size>
void vecsub(const Vec<size> &vec1, Vec<size> &vec)

vec -= vec1.

productOfSkewMatrices ​

#include <raisim/math.hpp>

cpp
void productOfSkewMatrices(
    const Vec<3> &vec1,
    const Vec<3> &vec2,
    Mat<3, 3> &mat)

mat = [vec1]x * [vec2]x, the product of the skew-symmetric (cross-product) matrices of the two vectors.

vecadd ​

#include <raisim/math.hpp>

cpp
void vecadd(const VecDyn &vec1, const VecDyn &vec2, VecDyn &vec)

vec = vec1 + vec2 over vec1.size() elements; vec must already have that size.

cpp
template <size_t size>
void vecadd(const Vec<size> &vec1, Vec<size> &vec)

vec += vec1.

cpp
void vecadd(const VecDyn &vec1, VecDyn &vec)

vec += vec1 over vec1.size() elements.

cpp
template <size_t size>
void vecadd(const Vec<size> &vec1, const Vec<size> &vec2, Vec<size> &vec)

vec = vec1 + vec2.

matadd ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m>
void matadd(const Mat<n, m> &mat1, Mat<n, m> &mat)

mat += mat1.

cpp
void matadd(const MatDyn &mat1, MatDyn &mat)

mat += mat1; both must have the same dimensions (not checked).

cpp
template <size_t n, size_t m>
void matadd(const Mat<n, m> &mat1, const Mat<n, m> &mat2, Mat<n, m> &mat)

mat = mat1 + mat2.

matsub ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m>
void matsub(const Mat<n, m> &mat1, Mat<n, m> &mat)

mat -= mat1.

cpp
template <size_t n, size_t m>
void matsub(const Mat<n, m> &mat1, const Mat<n, m> &mat2, Mat<n, m> &mat)

mat = mat1 - mat2.

mataddIdentity ​

#include <raisim/math.hpp>

cpp
template <size_t n>
void mataddIdentity(Mat<n, n> &mat)

Adds one to every diagonal element of mat.

add_aX ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void add_aX(double a, const Vec<size> &vec1, Vec<size> &vec)

vec += a * vec1.

add_b_p_aX ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void add_b_p_aX(
    double a,
    const Vec<size> &vec1,
    const Vec<size> &vec2,
    Vec<size> &vec)

vec = vec2 + a * vec1.

vecDot ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecDot(const Vec<size> &vec1, const Vec<size> &vec2, double &scalar)

scalar = vec1 . vec2 (dot product).

cpp
template <size_t size>
void vecDot(const double *vec1, const Vec<size> &vec2, double &scalar)

scalar = vec1 . vec2, where vec1 is an array of size doubles.

cpp
template <size_t size>
double vecDot(const double *vec1, const double *vec2)

Returns dot product of two arrays of size doubles.

cpp
template <size_t size>
double vecDot(const Vec<size> &vec1, const Vec<size> &vec2)

Returns dot product of vec1 and vec2.

cpp
double vecDot(const Vec<3> &vec1, const Vec<3> &vec2)

Returns dot product of vec1 and vec2.

cpp
void vecDot(const VecDyn &vec1, const VecDyn &vec2, double &scalar)

scalar = vec1 . vec2 over vec1.size() elements.

vecDivide ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecDivide(const Vec<size> &vec1, const double scalar, Vec<size> &vec)

vec = vec1 / scalar.

matDivide ​

#include <raisim/math.hpp>

cpp
template <size_t n, size_t m>
void matDivide(const Mat<n, m> &mat1, const double scalar, Mat<n, m> &mat)

mat = mat1 / scalar.

cross ​

#include <raisim/math.hpp>

cpp
void cross(const Vec<3> &vec1, const Vec<3> &vec2, Vec<3> &vec)

vec = vec1 x vec2 (cross product). vec must not alias the inputs.

cpp
void cross(const double *vec1, const Vec<3> &vec2, Vec<3> &vec)

vec = vec1 x vec2 with vec1 given as a 3-element array. vec must not alias the inputs.

cpp
void cross(const Vec<3> &vec1, const Vec<3> &vec2, double *vec)

vec = vec1 x vec2, written to a 3-element array that must not alias the inputs.

cpp
void cross(const double *vec1, const double *vec2, double *vec)

vec = vec1 x vec2 on 3-element arrays. vec must not alias the inputs.

cross_skip3_skip3_negative ​

#include <raisim/math.hpp>

cpp
void cross_skip3_skip3_negative(
    const double *vec1_skip,
    const double *vec2,
    double *vec)

vec = -(vec1 x vec2), where vec1_skip and vec are strided by 3 (elements 0, 3 and 6, e.g. a row of a column-major 3x3 matrix) and vec2 is contiguous.

crossThenAdd ​

#include <raisim/math.hpp>

cpp
void crossThenAdd(const Vec<3> &vec1, const Vec<3> &vec2, Vec<3> &vec)

vec += vec1 x vec2. vec must not alias the inputs.

cpp
void crossThenAdd(const Vec<3> &vec1, const Vec<3> &vec2, double *vec)

vec += vec1 x vec2, accumulated into a 3-element array that must not alias the inputs.

cpp
void crossThenAdd(const double *vec1, const double *vec2, double *vec)

vec += vec1 x vec2 on 3-element arrays. vec must not alias the inputs.

crossThenSub ​

#include <raisim/math.hpp>

cpp
void crossThenSub(const Vec<3> &vec1, const Vec<3> &vec2, Vec<3> &vec)

vec -= vec1 x vec2. vec must not alias the inputs.

crossMulScalarThenAdd ​

#include <raisim/math.hpp>

cpp
void crossMulScalarThenAdd(
    const double a,
    const Vec<3> &vec1,
    const Vec<3> &vec2,
    Vec<3> &vec)

vec += a * (vec1 x vec2). vec must not alias the inputs.

VecXMatVecThenAdd ​

#include <raisim/math.hpp>

cpp
void VecXMatVecThenAdd(
    const Vec<3> &vec1,
    const Mat<3, 3> &mat1,
    const Vec<3> &vec2,
    Vec<3> &vec)

vec += vec1 x (mat1 * vec2). vec must not alias vec1.

VecXMatVec ​

#include <raisim/math.hpp>

cpp
void VecXMatVec(
    const Vec<3> &vec1,
    const Mat<3, 3> &mat1,
    const Vec<3> &vec2,
    Vec<3> &vec)

vec = vec1 x (mat1 * vec2). vec must not alias vec1.

vecScalarMul ​

#include <raisim/math.hpp>

cpp
void vecScalarMul(const double scalar, const Vec<3> &vec, Vec<3> &product)

product = scalar * vec.

cpp
template <size_t size>
void vecScalarMul(
    const double scalar,
    const Vec<size> &vec,
    Vec<size> &product)

product = scalar * vec.

cpp
void vecScalarMul(const double scalar, const VecDyn &vec, VecDyn &product)

product = scalar * vec over vec.size() elements; product must already have that size.

cpp
void vecScalarMul(const double scalar, Vec<3> &product)

product *= scalar.

cpp
void vecScalarMul(const double scalar, VecDyn &product)

product *= scalar.

vecScalarMulThenAdd ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecScalarMulThenAdd(
    const double scalar,
    const double *vec,
    Vec<size> &sum)

sum += scalar * vec, where vec is an array of size doubles.

cpp
void vecScalarMulThenAdd(
    const double scalar,
    const double *vec,
    VecDyn &sum)

sum += scalar * vec over sum.size() elements of the array vec.

cpp
void vecScalarMulThenAdd(
    const double scalar,
    const VecDyn &vec1,
    const VecDyn &vec2,
    VecDyn &sum)

sum = scalar * vec1 + vec2 over sum.size() elements (assigns, despite the name).

cpp
void vecScalarMulThenAdd(
    const double scalar,
    const VecDyn &vec,
    VecDyn &sum)

sum += scalar * vec over sum.size() elements.

cpp
template <size_t size>
void vecScalarMulThenAdd(
    const double scalar,
    const Vec<size> &vec,
    Vec<size> &sum)

sum += scalar * vec.

vecScalarMulInPlaceThenAdd ​

#include <raisim/math.hpp>

cpp
void vecScalarMulInPlaceThenAdd(
    const double scalar,
    VecDyn &vec,
    VecDyn &sum)

Scales vec in place by scalar, then sum += vec, over sum.size() elements.

vecvecCwiseMulThenAdd ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecvecCwiseMulThenAdd(
    const Vec<size> &vec1,
    const Vec<size> &vec2,
    Vec<size> &sum)

sum += vec1 .* vec2 (element-wise product).

cpp
void vecvecCwiseMulThenAdd(
    const VecDyn &vec1,
    const VecDyn &vec2,
    VecDyn &sum)

sum += vec1 .* vec2 (element-wise product) over vec1.size() elements.

vecvecCwiseMulThenSub ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecvecCwiseMulThenSub(
    const Vec<size> &vec1,
    const Vec<size> &vec2,
    Vec<size> &sum)

sum -= vec1 .* vec2 (element-wise product).

cpp
void vecvecCwiseMulThenSub(
    const VecDyn &vec1,
    const VecDyn &vec2,
    VecDyn &sum)

sum -= vec1 .* vec2 (element-wise product) over vec1.size() elements.

vecvecScalarCwiseMulThenSub ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecvecScalarCwiseMulThenSub(
    double scalar,
    const Vec<size> &vec1,
    const Vec<size> &vec2,
    Vec<size> &sum)

sum -= scalar * (vec1 .* vec2) (element-wise product).

vecvecCwiseMul ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecvecCwiseMul(
    const Vec<size> &vec1,
    const Vec<size> &vec2,
    Vec<size> &sum)

sum = vec1 .* vec2 (element-wise product).

cpp
void vecvecCwiseMul(const VecDyn &vec1, const VecDyn &vec2, VecDyn &sum)

sum = vec1 .* vec2 (element-wise product) over vec1.size() elements.

vecScalarMulThenSub ​

#include <raisim/math.hpp>

cpp
template <size_t size>
void vecScalarMulThenSub(
    const double scalar,
    const Vec<size> &vec,
    Vec<size> &sum)

sum -= scalar * vec.

cpp
template <size_t size>
void vecScalarMulThenSub(
    const double scalar,
    const double *vec,
    Vec<size> &sum)

sum -= scalar * vec, where vec is an array of size doubles.

skewSymMat ​

#include <raisim/math.hpp>

cpp
void skewSymMat(const Vec<3> &vec, Mat<3, 3> &mat)

mat = [vec]x, the skew-symmetric matrix with mat * a = vec x a.

vecTransposeMatVecMul ​

#include <raisim/math.hpp>

cpp
void vecTransposeMatVecMul(
    const Vec<3> &vec,
    const Mat<3, 3> &mat,
    double &scalar)

scalar = vec^T * mat * vec.

addCentrifugalTerm ​

#include <raisim/math.hpp>

cpp
void addCentrifugalTerm(
    const Vec<3> &omega,
    const Vec<3> &displacement,
    Vec<3> &linAcc)

linAcc += omega x (omega x displacement), the centripetal acceleration of a point at displacement.

rotationIntegration ​

#include <raisim/math.hpp>

cpp
void rotationIntegration(
    Mat<3, 3> &rotationMatrix,
    double dt,
    const Vec<3> &angVel)

Integrates an orientation over dt at a constant angular velocity using the exponential map: rotationMatrix = exp([angVel]x * dt) * rotationMatrix. The angular velocity is therefore expressed in the reference (world) frame. Nothing is done if |angVel| * dt < 1e-11. The result is not re-orthonormalized.

Parameters

ParameterDescription
rotationMatrix (in, out)orientation to update
dt (in)time step
angVel (in)angular velocity
cpp
void rotationIntegration(
    const Mat<3, 3> &initial,
    Mat<3, 3> &final,
    double dt,
    const Vec<3> &angVel)

Like the in-place rotationIntegration() but writes final = exp([angVel]x * dt) * initial (a copy of initial if |angVel| * dt < 1e-11).

cpp
void rotationIntegration(
    Mat<3, 3> &rotationMatrix,
    double dt,
    const double *angVel)

In-place rotationIntegration() with angVel given as a 3-element array.

squaredNormOfDiff ​

#include <raisim/math.hpp>

cpp
template <size_t size>
double squaredNormOfDiff(const Vec<size> &vec1, const Vec<size> &vec2)

Returns squared Euclidean norm of vec1 - vec2.

zaxisToRotMat ​

#include <raisim/math.hpp>

cpp
void zaxisToRotMat(const Vec<3> &zaxis, Mat<3, 3> &rotMat)

Computes the rotation by the smallest angle that maps the z axis (0, 0, 1) onto zaxis.

Parameters

ParameterDescription
zaxis (in)target direction; must be a unit vector
rotMat (out)identity if zaxis is (0, 0, 1), a rotation by pi about x if it is (0, 0, -1)

addToDiagonal ​

#include <raisim/math.hpp>

cpp
void addToDiagonal(const VecDyn &vec, MatDyn &mat)

Adds vec to the first vec.size() diagonal elements of mat. The dimensions are checked only in debug builds.

Prod_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T1, class T2>
double Prod_func(const T1 &exp1, const T2 &exp2, size_t i, size_t j)

Evaluates element (i, j) of the matrix product exp1 * exp2.

Sum_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T1, class T2>
double Sum_func(const T1 &exp1, const T2 &exp2, size_t i, size_t j)

Evaluates element (i, j) of exp1 + exp2.

Sub_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T1, class T2>
double Sub_func(const T1 &exp1, const T2 &exp2, size_t i, size_t j)

Evaluates element (i, j) of exp1 - exp2.

Div_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T1, class T2>
double Div_func(const T1 &exp1, const T2 &exp2, size_t i, size_t j)

Evaluates element (i, j) of the element-wise quotient exp1 / exp2.

Div_S_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T>
double Div_S_func(const T &exp1, double scalar, size_t i, size_t j)

Evaluates element (i, j) of exp1 / scalar.

Prod_S_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T>
double Prod_S_func(const T &exp1, double scalar, size_t i, size_t j)

Evaluates element (i, j) of exp1 * scalar.

Sum_S_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T>
double Sum_S_func(const T &exp1, double scalar, size_t i, size_t j)

Evaluates element (i, j) of exp1 + scalar.

Sub_S_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T>
double Sub_S_func(const T &exp1, double scalar, size_t i, size_t j)

Evaluates element (i, j) of exp1 - scalar.

Sub_SL_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T>
double Sub_SL_func(double scalar, const T &exp1, size_t i, size_t j)

Evaluates element (i, j) of scalar - exp1. Left-scalar evaluators exist because - and / do not commute.

Div_SL_func ​

#include <raisim/math/Operation.hpp>

cpp
template <class T>
double Div_SL_func(double scalar, const T &exp1, size_t i, size_t j)

Evaluates element (i, j) of scalar / exp1.

operator- ​

#include <raisim/math/Operation.hpp>

cpp
template <typename T>
Sub_S_op<T> operator-(MatExpr<T> const &u, double scalar)
cpp
template <typename T>
Sub_SL_op<T> operator-(double scalar, MatExpr<T> const &u)

operator/ ​

#include <raisim/math/Operation.hpp>

cpp
template <typename T>
Div_S_op<T> operator/(MatExpr<T> const &u, double scalar)
cpp
template <typename T>
Div_SL_op<T> operator/(double scalar, MatExpr<T> const &u)

getInertialAssumingUniformDensity ​

#include <raisim/object/ArticulatedSystem/JointAndBodies.hpp>

cpp
void getInertialAssumingUniformDensity(
    Shape::Type shape,
    const Vec<4> &shapeParam,
    const Mat<3, 3> &rot,
    double density,
    double &mass,
    Mat<3, 3> &inertia)

Compute the mass and inertia of a primitive with uniform density. Mass is 0 for other shapes.

Parameters

ParameterDescription
shape (in)Sphere, Box, Capsule or Cylinder (the cylinder/capsule axis is the local z axis)
shapeParam (in)sphere {radius}, box {lx, ly, lz}, cylinder/capsule {radius, length of the cylindrical part} [m]
rot (in)orientation of the shape; the inertia is returned as rot * I * rot^T
density (in)density [kg/m^3]
mass (out)mass [kg]
inertia (out)inertia about the shape center [kg m^2]

motorTorqueBounds ​

#include <raisim/object/ArticulatedSystem/MotorOperatingRegion.hpp>

cpp
MotorTorqueBounds motorTorqueBounds(
    double stallTorque,
    double backEmfDamping,
    double peakTorque,
    double speed)

motorTorqueBounds() with the motor constants evaluated once: both voltage limits are lines of slope -backEmfDamping through +/-stallTorque.

Parameters

ParameterDescription
stallTorque (in)DcMotorParameters::stallTorque() [Nm]
backEmfDamping (in)DcMotorParameters::backEmfDamping() [Nm s/rad]
peakTorque (in)DcMotorParameters::peakTorque [Nm]
speed (in)motor (rotor-side) speed [rad/s]

Returns the admissible torque interval and the bound that limits each side

cpp
MotorTorqueBounds motorTorqueBounds(
    const DcMotorParameters &motor,
    double speed)

Admissible motor torque at motor speed speed [rad/s]. Above the speed at which even full reverse voltage cannot keep the current below the peak, the voltage band no longer reaches the peak-torque band: every admissible voltage drives more than the peak current against the back EMF. The saturated core caps the torque at the peak torque, so the interval collapses to the peak torque that opposes the motion (-peak above the forward overspeed, +peak below the reverse one).

Parameters

ParameterDescription
motor (in)motor parameters
speed (in)motor (rotor-side) speed [rad/s]

Returns the admissible torque interval and the bound that limits each side

clipMotorTorque ​

#include <raisim/object/ArticulatedSystem/MotorOperatingRegion.hpp>

cpp
double clipMotorTorque(
    const DcMotorParameters &motor,
    double speed,
    double torque,
    MotorSaturation *saturation=nullptr)

Clips a motor torque request to the operating region at motor speed speed.

Parameters

ParameterDescription
motor (in)motor parameters
speed (in)motor (rotor-side) speed [rad/s]
torque (in)requested motor torque [Nm]
saturation (out)the bound that limited the torque (NONE if the request was admissible)

Returns the admissible motor torque closest to the request

motorOperatingRegionViolation ​

#include <raisim/object/ArticulatedSystem/MotorOperatingRegion.hpp>

cpp
double motorOperatingRegionViolation(
    const DcMotorParameters &motor,
    double speed,
    double torque)

Parameters

ParameterDescription
motor (in)motor parameters
speed (in)motor (rotor-side) speed [rad/s]
torque (in)motor torque [Nm]

Returns how far [Nm] the torque lies outside the operating region at speed (zero inside)

toString ​

#include <raisim/sensors/CameraLens.hpp> #include <raisim/sensors/Sensors.hpp>

cpp
std::string toString(CameraProjectionType projection)

Returns "pinhole" or "fisheye_equidistant".

cpp
static std::string toString(Sensor::Type type)

Returns Lower-case name of a sensor type ("rgb", "depth", "imu", "spinning_lidar", or "unknown").

cameraDistortionModel ​

#include <raisim/sensors/CameraLens.hpp>

cpp
std::string cameraDistortionModel(CameraProjectionType projection)

Returns The distortion-model name for a projection: "equidistant" for fisheye, "none" for pinhole.

cameraLensLowerAscii ​

#include <raisim/sensors/CameraLens.hpp>

cpp
std::string cameraLensLowerAscii(std::string value)

Returns A copy of the string with ASCII letters converted to lower case.

cameraProjectionTypeFromString ​

#include <raisim/sensors/CameraLens.hpp>

cpp
CameraProjectionType cameraProjectionTypeFromString(const std::string &value)

Parse a projection name (case-insensitive).

Parameters

ParameterDescription
value (in)"fisheye", "fisheye_equidistant", "equidistant", "opencv_fisheye" or "kannala_brandt" select FISHEYE_EQUIDISTANT; anything else selects PINHOLE.

Returns The parsed projection type.

resolveCameraIntrinsics ​

#include <raisim/sensors/CameraLens.hpp>

cpp
CameraIntrinsics resolveCameraIntrinsics(
    const CameraLensModel &lens,
    int width,
    int height,
    double hFOV)

Fill in the intrinsics that the lens leaves unset. Missing focal lengths become fx = fy = (width/2) / tan(hFOV/2) for pinhole and (width/2) / (hFOV/2) for fisheye; a missing principal point becomes the image center.

Parameters

ParameterDescription
lens (in)Lens model.
width (in)Image width in pixels.
height (in)Image height in pixels.
hFOV (in)Horizontal field of view in radians.

Returns The resolved intrinsics in pixels.

cameraMatrix ​

#include <raisim/sensors/CameraLens.hpp>

cpp
std::array<double, 9> cameraMatrix(
    const CameraLensModel &lens,
    int width,
    int height,
    double hFOV)

Returns The 3x3 camera matrix K of the resolved intrinsics (see resolveCameraIntrinsics()), stored row-major: {fx, 0, cx, 0, fy, cy, 0, 0, 1}.

fisheyeDistortionCoefficients ​

#include <raisim/sensors/CameraLens.hpp>

cpp
std::array<double, 4> fisheyeDistortionCoefficients(const CameraLensModel &lens)

Returns The fisheye distortion coefficients {k1, k2, k3, k4}.

Variables ​

gMaterialChangeCounter ​

#include <raisim/collision/material_dirty.hpp>

cpp
std::uint64_t gMaterialChangeCounter

Global material change counter used to invalidate cached material data.

RSEVERITY_INFO ​

#include <raisim/raisim_message_logger.hpp>

cpp
constexpr int RSEVERITY_INFO

Informational message severity.

RSEVERITY_WARN ​

#include <raisim/raisim_message_logger.hpp>

cpp
constexpr int RSEVERITY_WARN

Warning message severity.

RSEVERITY_FATAL ​

#include <raisim/raisim_message_logger.hpp>

cpp
constexpr int RSEVERITY_FATAL

Fatal message severity (invokes the fatal callback).

RaiSim — physics for robotics and AI.