discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

multmatrix() argument

R
Ronaldo
Mon, Jul 25, 2016 11:02 PM

OpenSCAD language has a rare leniency with programming errors. That is nice
but dangerous if the its behavior is not properly documented. I found by
mistake that multmatrix() accepts 3x3 matrix as well. And do the expected
linear transform. So, if R is a 3x3 rotation matrix, multmatrix(R) cube()
will rotate correctly the cube. More than that, it accepts even non-uniform
"matrices" like:

M = [ [ [ -1, 0, 0, 0], [0] , [0,0,-1] ];

to do a 90 degree rotation about y axis. It seems that multmatrix() fill out
the blanks with the corresponding 0's and 1's borrowed from the identity
matrix in this case. Who knows?

Although this last example is a bit odd, it would be nice to allow the use
of 3x3 matrices in multmatrix() as a feature and not just as a complacent
work around. But this should be documented to become a feature. Otherwise we
cannot rely on it.

--
View this message in context: http://forum.openscad.org/multmatrix-argument-tp17983.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

OpenSCAD language has a rare leniency with programming errors. That is nice but dangerous if the its behavior is not properly documented. I found by mistake that multmatrix() accepts 3x3 matrix as well. And do the expected linear transform. So, if R is a 3x3 rotation matrix, multmatrix(R) cube() will rotate correctly the cube. More than that, it accepts even non-uniform "matrices" like: M = [ [ [ -1, 0, 0, 0], [0] , [0,0,-1] ]; to do a 90 degree rotation about y axis. It seems that multmatrix() fill out the blanks with the corresponding 0's and 1's borrowed from the identity matrix in this case. Who knows? Although this last example is a bit odd, it would be nice to allow the use of 3x3 matrices in multmatrix() as a feature and not just as a complacent work around. But this should be documented to become a feature. Otherwise we cannot rely on it. -- View this message in context: http://forum.openscad.org/multmatrix-argument-tp17983.html Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Tue, Jul 26, 2016 1:15 AM

Nice catch. I read somewhere --- not specefically for OpenScad but as a
general description --- that feeding multmatrix with a 3x3 is much faster
than with a 4x4. So if OpenScad does follow that behavior, it'd be nice to
have 3x3 for multmatrix as a regular argument when 4x4 is not needed.


$  Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )

View this message in context: http://forum.openscad.org/multmatrix-argument-tp17983p17984.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Nice catch. I read somewhere --- not specefically for OpenScad but as a general description --- that feeding multmatrix with a 3x3 is much faster than with a 4x4. So if OpenScad does follow that behavior, it'd be nice to have 3x3 for multmatrix as a regular argument when 4x4 is not needed. ----- $ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 );   $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf ) -- View this message in context: http://forum.openscad.org/multmatrix-argument-tp17983p17984.html Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Tue, Jul 26, 2016 10:19 AM

To see the code with default values, just display the CSG tree.

M =  [ [ -1, 0, 0, 0], [0] , [0,0,-1] ];
multmatrix(M) cube();

gets

group() {
multmatrix([[-1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]) {
cube(size = [1, 1, 1], center = false);
}
}

--
View this message in context: http://forum.openscad.org/multmatrix-argument-tp17983p17985.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

To see the code with default values, just display the CSG tree. > M = [ [ -1, 0, 0, 0], [0] , [0,0,-1] ]; > multmatrix(M) cube(); gets > group() { > multmatrix([[-1, 0, 0, 0], [0, 1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]) { > cube(size = [1, 1, 1], center = false); > } > } -- View this message in context: http://forum.openscad.org/multmatrix-argument-tp17983p17985.html Sent from the OpenSCAD mailing list archive at Nabble.com.