discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] New coordinates after rotation and translation

JB
Jordan Brown
Mon, Jan 7, 2019 7:26 PM

On 1/7/2019 9:42 AM, Maurice van Peursem wrote:

Is there an easy way to get the new coordinates of a point after a few
rotations and translations?

Simple answer:  No.

More complex answer:  You can generate the matrices yourself and
multiply them out.

The documentation for multmatrix() is helpful in generating the
matrices:
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#multmatrix

The Wikipedia article is pretty technical but looks to have a good set
of patterns:  https://en.wikipedia.org/wiki/Transformation_matrix

Capsule summary:  Every transformation is equivalent to a particular 4x4
matrix.  Multiplying the point by the transformation matrix yields the
transformed point.  Multiplying several transformation matrices together
yields a transformation matrix that represents all of the
transformations.  OpenSCAD does matrix multiplication natively; you can
just say "p*tm" where p is a point as an [x,y,z] vector and tm is a
transformation matrix, and OpenSCAD will do the right thing and yield a
new point.

On 1/7/2019 9:42 AM, Maurice van Peursem wrote: > Is there an easy way to get the new coordinates of a point after a few > rotations and translations? Simple answer:  No. More complex answer:  You can generate the matrices yourself and multiply them out. The documentation for multmatrix() is helpful in generating the matrices: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#multmatrix The Wikipedia article is pretty technical but looks to have a good set of patterns:  https://en.wikipedia.org/wiki/Transformation_matrix Capsule summary:  Every transformation is equivalent to a particular 4x4 matrix.  Multiplying the point by the transformation matrix yields the transformed point.  Multiplying several transformation matrices together yields a transformation matrix that represents all of the transformations.  OpenSCAD does matrix multiplication natively; you can just say "p*tm" where p is a point as an [x,y,z] vector and tm is a transformation matrix, and OpenSCAD will do the right thing and yield a new point.