Unlike other langages (such as Matlab, Python...) there is no native functions for matrix and vector operations in C.
With the particularity of our indexing convention the matrix and vector manipulation is a little different from the usual code you may have. So we provide some functions that do the operations for you.
Most of the functions ends with "_1" or "_0". This suffix indicates whether the function is dedicated to vector and matrix using our convention or not (i.e. starting at 0 or 1).
Some functions have been set allowing you to get allocated matrix and vector. For matrices, the memory allocated is contiguous. See the following functions:
Replacing the "d" letter by "i" gives you matrix and vectors of integers.
All the memory that you asked must be freed by the corresponding functions:
To compute the norm (ie. the length) of a vector uses one of the following functions:
To get the unit vector aligned with a vector uses:
To multiply a vector by a scalar, uses:
For the scalar product between two vectors uses:
For the dot product between matrix and vector uses:
For the dot product between matrices uses:
For the cross product between two vectors use:
To get the transpose of matrix uses:
Others utility functions have been created over time (and still will be created). Explore the following headers:
If some is missing feel free to contribute.
In MBsysC the convention has been taken to start filling arrays (vectors and matrices) at the index number "1" (instead of "0"). This choice has been done to help the user accessing to its joints (and also historical reason).
Indeed the joint numbering in the graphical editor of the model (MBsysPAD) start a "1", in his code the user can get the coordinate of the joint by reading MbsData::q with the same index:
double q1_coord = mbs_data->q[1]
This convention have been extended to the whole (or almost) source code.