Implementation:Google deepmind Mujoco User Util
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Math Utilities |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Provides low-level mathematical and utility functions for vector operations, quaternion math, string parsing, and numeric validation used throughout the user module.
Description
user_util.cc contains foundational utility functions used across the MuJoCo user module. It implements vector operations (mjuu_setvec, mjuu_dot3, mjuu_dist3, mjuu_normvec, mjuu_scalevec), matrix address computation (mjuu_matadr), numeric validation (mjuu_defined using isnan), and provides overloaded versions for both double and float types. The file includes a macOS-specific workaround for locale-sensitive strtof/strtod functions to ensure consistent numeric parsing across platforms.
Usage
Used as a utility library by most files in the user and xml modules for basic mathematical operations and numeric conversions during model specification and compilation.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/user/user_util.cc
- Lines: 1-1282
Key Functions
bool mjuu_defined(double num);
int mjuu_matadr(int g1, int g2, int n);
void mjuu_setvec(double* dest, double x, double y, double z, double w);
void mjuu_setvec(float* dest, double x, double y, double z, double w);
void mjuu_setvec(double* dest, double x, double y, double z);
double mjuu_dot3(const double* a, const double* b);
double mjuu_dist3(const double* a, const double* b);
double mjuu_normvec(double* vec, int n);
void mjuu_scalevec(double* res, const double* vec, double s, int n);
Import
#include "user/user_util.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| dest | double*/float* | Yes | Destination vector for set/copy operations |
| vec | double*/float* | Yes | Input vector for normalization/scaling |
| n | int | Yes | Vector dimension or matrix size |
| num | double | Yes (for mjuu_defined) | Numeric value to check for NaN |
Outputs
| Name | Type | Description |
|---|---|---|
| bool | bool | Whether a numeric value is defined (not NaN) |
| double | double | Computed dot product, distance, or previous vector length |
| void | void | Vectors modified in-place |