Feature: expand transformation matrix to 4x4xN ?
Hi David
What do you think about expanding the transformation matrices to a third dimension [4x4xN]?
That would introduce the possibility to transform multiple points [Nx3], vectors [Nx3], etc. with multiple transformation matrices [4x4xN].
Kind regards
Hi,
yes, sounds good! I think some functions (maybe written by you?) already follow this convention. The main functions to update would be the "transformXXX"ones. Do you see others?
I think the following files:
composeTransforms3d.m createBasisTransform3d.m createRotation*.m createScaling3d.m createTranslation3d.m eulerAnglesToRotation3d.m isTransform3d.m recenterTransform3d.m rotation3dAxisAndAngle.m rotation3dToEulerAngles.m transform*3d.m
Actually more work than I thought. ;-)
One question is: what is the most elegant, efficient and consistent way to implement this feature?
Other question is: what conventions should be used for multiple input variables? For example for transformLine3d.m Input: Line [1x6], TFM [4x4] -> Output: Line [1x6] Input: Line [1x6], TFM [4x4xN] -> Output: Line [Nx6] Input: Line [Nx6], TFM [4x4xN] -> Output: Line [Nx6] Input: Line [Nx6], TFM [4x4] -> Output: Line [Nx6] Input: Line [Mx6], TFM [4x4xN] -> Output: error
Kind regards
Hi,
yes, the number of functions devoted to transforms start to be large! However, all the creation functions can be left as is for the moment. This reduces the work.
The output for multiple inputs may be problematic... In the case of M lines and N transforms, a possible solution would be to output a M-by-6-by-N array (keeping last index for the transformation index).
best regards, David
Matlab introduced a new function that might help https://www.mathworks.com/help/matlab/ref/pagemtimes.html However, I don't know when I will have the time to give it a try.
Other question is: what conventions should be used for multiple input variables? For example for transformLine3d.m Input: Line [1x6], TFM [4x4] -> Output: Line [1x6] Input: Line [1x6], TFM [4x4xN] -> Output: Line [Nx6] Input: Line [Nx6], TFM [4x4xN] -> Output: Line [Nx6] Input: Line [Nx6], TFM [4x4] -> Output: Line [Nx6] Input: Line [Mx6], TFM [4x4xN] -> Output: error
If you are interested, with respect to the above, in my opinion you should aim to reproduce something comparable to the implicit expansion Matlab will do nowadays with incompatible sizes (https://uk.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html)
Hi, yes, I strongly agree with following the Matlab convention for implicit conventions. The bsxfun function is also used is several functions internally.
Reconsidering the question today, a solution could be as follow:
Input: Line [1x6], TFM [4x4] -> Output: Line [1x6] Input: Line [Nx6], TFM [4x4] -> Output: Line [Nx6] Input: Line [1x6], TFM [4x4xN] -> Output: Line [1x6xN] Input: Line [Mx6], TFM [4x4xN] -> Output: Line [Mx6xN]
This way, we ensure consistent dimension of output argument.
Two improvements may be added:
- when both inputs have same N, the use of an additionnal option may force to combine only inputs with same index, like keeping only the diagonal of the MxN matrix. I used such an approach for the distancePoints function
- it could useful to have a squeeze function that transforms 1x6xN arrays into Nx6 arrays. Maybe something like "squeezeGeometry"?. Principle would be to squeeze all dimensions except the second one.