New Matrix Functions

(Matrix image cour­tesy of mavad­dat.)

In now-merged PR 8603 new FreeCAD con­trib­u­tor Daniel-Khod­abakhsh devel­oped a new set of matrix-con­struc­tion con­ve­nience func­tions that are pro­vide a much nicer API than the orig­i­nal matrix cre­ation methods.

The fol­low­ing func­tions were added which are short­hand for the create function:

New func­tionObject typeAna­log
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 fol­low­ing matrix func­tions were also added. These func­tions are fol­low­ing the same pat­tern pre­vi­ous­ly estab­lished by the exist­ing minvert and mscale.

New func­tionDescrip­tion
mrotateRotate giv­en object.
mrotatexRotate giv­en object around the X‑axis.
mrotateyRotate giv­en object around the Y‑axis.
mrotatezRotate giv­en object around the Z‑axis.
mtranslateTrans­late giv­en object (Rotation objects will be returned as a Placement object)

These func­tions return the same type of object which was sup­plied with the excep­tion of mtranslate.

The func­tions can be chained togeth­er like so:

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

Thanks to Daniel-Khod­abakhsh for this valu­able con­tri­bu­tion to FreeCAD’s Expres­sion API.

2 responses to “New Matrix Functions”

  1. This seems to be for expres­sions, not Python.

    1. Yes indeed! Thanks!

%d bloggers like this: