Dear subscribers,

a new function for the MATLAB programming language, implementing an
user-friendly and versatile algorithm to define Cartesian reference frames
based on point positions, is freely available on the following web server:

   - MATLAB Central > File Exchange > Controls and Systems Modeling >
Mechanical Modeling
   - Defining Cartesian Reference Systems based on Point Positions

 Defining Cartesian Reference Systems based on Point Positions
                        By Paolo de Leva

Cartesian Reference System, Frame, Orientation matrix, Biomechanics

Versatile algorithm defining Cartesian reference systems based on the
position of at least 3 points.

The main function included in the attached file is called REFSYS. The
algorithm implemented in this function can be useful in motion analysis
(biomechanics, bioengineering).

When you know the 3-D position of at least three non-collinear points, you
can define a Cartesian reference system based on these positions.

REFSYS builds an orientation matrix R representing the orientation of a
right handed 3-D Cartesian reference system, based on the position of at
least 3 and at most 6 non collinear points.

REFSYS accepts as input block arrays of vectors. In this case, it returns a
block array of orientation matrices (see below).

Several different reference system orientations can be defined by the same
set of points. For instance, the same three points can be used to define 72
different orientations for a right-handed 3-D Cartesian reference system!
Three non collinear points define a triangle and a plane, which in turn
define seven lines (six are parallel to the three sides and the three
heights of the triangle, and the seventh is normal to the plane; see Figure
1 in the attached "screenshot"). Since for each line there are two opposite
directions, any of the Cartesian axes can be assigned 14 different
directions. And any of these 14 directions is normal to 4 or 12 of the other
directions, all of which can be used to define the other axes…

REFSYS is extremely versatile, and with a simple syntax allows you to define
the reference system(s) as you prefer, in a single step.

Its input arguments include three oriented distances (d1, d2, and d3),
obtained from the known point positions with vector subtractions. For
instance, if pA and pB are the positions of two points A and B, pB-pA (or
-pA+pB) is the oriented distance from point A to point B. Since d1 may
coincide with d3, three points are enough to define the three distances.

For instance, three position vectors (pA, pB, pC) might be used as follows:

R = REFSYS(-pA+pB, -pB+pC, 'y', -pA+pB, 'z', DIM)

and six position vectors (pA, pB, pC, pD, pE, pF) might be used as follows:

R = REFSYS(-pA+pB, -pC+pD, 'y', -pE+pF, 'z', DIM)

where DIM is the dimension along which the vectors are contained.

The direction of the first axis ('y' in the above examples) is defined by
the vector product d1 × d2. The direction of the second axis ('z' in the
above example) is defined by the rejection of d3 from the first axis,
coinciding with the projection of d3 on the plane defined by d1 and d2. The
third axis forms with the others a right handed orthogonal reference system.
A more detailed explanation of the function syntax and the rules used to
build the output array R can be found on the REFSYS help text.

If pA, pB, etc. are 3-by-1 matrices, DIM = 1 and R is a single 3-by-3
orientation matrix.

The arrays pA, pB, etc. can have any size, provided they contain 3-element
position vectors along one of their dimensions (DIM). For instance, if they
are Nf-by-3 matrices, containing Nf positions of a moving point, sampled
with a stereophotogrammetric motion capture system, R is a Nf-by-3-by-3
array, containing Nf orientation matrices. See REFSYS help for details about
the format of the input and output arrays.

Any matrix or array of orientation matrices R obtained with REFSYS can be
used to perform transformations. Multiple vector transformations can be
obtained by multiplying an array of orientation matrices by an array of
vectors. This "multi-product" can be performed easily, in a single step and
with no loops, by calling function MULTIPROD.

MULTIPROD is a powerful generalization for N-D arrays of the MATLAB function
MTIMES and the matrix multiplication operator (*). Obviously, MULTIPROD has
a broad field of potential applications. For instance, it can be used to
perform vector algebra (see package "Matlab Central > File Exchange > Vector
algebra for multidimensional arrays of vectors"). Thus, in my opinion it
deserved a separate introduction and I published it in a separate package:
"Matlab Central > File Exchange > Multiplying two N-D arrays of matrices,
vectors or scalars".

A few sample functions are included in this package. They determine the
orientation of anatomical reference systems for segments of the human body
(pelvis, thigh, shank, foot), according to the definitions given by:
Cappozzo et al. (1995). Position and orientation in space of bones during
movement: anatomical frame definition and determination. Clinical
Biomechanics, 10, 171-178.

The code (testREFSYS) I used to test the function output is included as

REFSYS calls UNIT, a function included in the vector algebra toolbox
("Matlab Central > File Exchange > Vector algebra for multidimensional
arrays of vectors").


With my kindest regards,

Paolo de Leva
Department of Human Movement and Sport Sciences
University Institute of Movement Science