[Closed] Reset Scale of a matrix
Is it possible to reset the scale of a matrix the same way as ResetScale $
works for objcets?
Here is an example:
(
mat01 = (matrix3 [-0.95407,0.14169,-0.263958] [-0.211014,-0.943264,0.256371] [0.212657,-0.300295,-0.929839] [-2.59766,-51.5166,16.7929])
format "mat01 scale: % \n" mat01.scale --> [-1,-1,-1]
p = point transform:mat01
ResetScale p
mat02 = p.transform
format "mat02 scale: % \n" mat02.scale --> [1,1,1]
-- "mat02 is the desired result - scale is [1,1,1] and the axes directions are not changed"
-- (matrix3 [0.95407,-0.14169,0.263958] [0.211014,0.943264,-0.256371] [-0.212657,0.300295,0.929839] [-2.59766,-51.5166,16.7929])
)
Based on this documentation:
You want to multiply by a matrix containing the inverse of your current scale to ‘undo’ the scale and set it back to 1:
mat01 = (matrix3 [-0.95407,0.14169,-0.263958] [-0.211014,-0.943264,0.256371] [0.212657,-0.300295,-0.929839] [-2.59766,-51.5166,16.7929])
format "mat01 scale: % \n" mat01.scale --> [-1,-1,-1]
normalizer = (matrix3 [1/mat01.scale.x,0,0] [0,1/mat01.scale.y,0] [0,0,1/mat01.scale.z] [0,0,0])
mat01 = mat01 * normalizer
format "mat01 scale: % \n" mat01.scale --> [1,1,1]
Hi!
Maybe I am doing something wrong, but your code changes the direction of the axes of the point helper. Check this:
(
mat01 = (matrix3 [-0.95407,0.14169,-0.263958] [-0.211014,-0.943264,0.256371] [0.212657,-0.300295,-0.929839] [-2.59766,-51.5166,16.7929])
format "mat01 scale: % \n" mat01.scale --> [-1,-1,-1]
p = point transform:mat01 wirecolor:red axistripod:true cross:false
normalizer = (matrix3 [1/mat01.scale.x,0,0] [0,1/mat01.scale.y,0] [0,0,1/mat01.scale.z] [0,0,0])
mat01 = mat01 * normalizer
format "mat01 scale: % \n" mat01.scale --> [1,1,1]
p1 = point transform:mat01 wirecolor:yellow axistripod:true cross:false
-- ResetScale p
--
-- mat02 = p.transform
-- format "mat02 scale: % \n" mat02.scale --> [1,1,1]
-- "mat02 is the desired result - scale is [1,1,1] and the axes directions are not changed"
-- (matrix3 [0.95407,-0.14169,0.263958] [0.211014,0.943264,-0.256371] [-0.212657,0.300295,0.929839] [-2.59766,-51.5166,16.7929])
)
The X, Y, Z axis of the point helper should points in the same direction as before to reset the scale of the mat01.
@Klvnk’s solution is definitely better!
Matrix math is always tricky – each system is a little different in terms of how they implement it – how they build their matrices and the order of matrix multiplication. I’m guessing for the math I gave you that you would need to flip the multiplication order (matrix multiplication is non-commutative) or something else simple. Since it’s already solved, I won’t bother fixing it
another alternative is
mat02 = mat01.rotationpart as matrix3;
mat02.translation = mat01.translation;