Feature

New Matrix Functions

Code API 2 min Chris Hennes
feature cover
Matrix
Matrix

Matrix image courtesy of mavaddat .

In now-merged PR 8603 new FreeCAD contributor Daniel-Khodabakhsh developed a new set of matrix-construction convenience functions that are provide a much nicer API than the original matrix creation methods.

The following functions were added which are shorthand for the create function:

New functionObject typeAnalog
matrix(...)Matrixcreate(<<matrix>>; ...)
placement(...)Placementcreate(<<placement>>; ...)
rotation(...)Rotationcreate(<<rotation>>; ...)
rotationx(angle)Rotationcreate(<<rotation>>; create(<<vector>>; 1; 0; 0); angle)
rotationy(angle)Rotationcreate(<<rotation>>; create(<<vector>>; 0; 1; 0); angle)
rotationz(angle)Rotationcreate(<<rotation>>; create(<<vector>>; 0; 0; 1); angle)
translationm(x; y; z)Matrixcreate(<<matrix>>; 1; 0; 0; x; 0; 1; 0; y; 0; 0; 1; z; 0; 0; 0; 1)
vector(...)Vectorcreate(<<vector>>; ...)

The following matrix functions were also added. These functions are following the same pattern previously established by the existing minvert and mscale.

New functionDescription
mrotateRotate given object.
mrotatexRotate given object around the X-axis.
mrotateyRotate given object around the Y-axis.
mrotatezRotate given object around the Z-axis.
mtranslateTranslate given object (Rotation objects will be returned as a Placement object)

These functions return the same type of object which was supplied with the exception of mtranslate.

The functions can be chained together like so:

=mtranslate(mrotatex(placement(vector(1; 2; 3); rotation(0; 0; 0)); 45); 1; 2; 3)

Thanks to Daniel-Khodabakhsh for this valuable contribution to FreeCAD`s Expression API.