Two transformations in one : matrix « Number « Ruby






Two transformations in one


require "matrix"
sx,sy = 2.0, 3.0;
unit = 2
scale = Matrix[[sx,0], [0, sy]]
scale*unit             # => [2.0, 3.0]: scaled point

theta = Math::PI/2     # 90 degrees
rotate = Matrix[[Math.cos(theta), -Math.sin(theta)],
                [Math.sin(theta),  Math.cos(theta)]]
rotate*unit            # [-1.0, 1.0]: 90 degree rotation


scale * (rotate*unit)  # [-2.0, 3.0]

 








Related examples in the same category

1.matrix in action
2.This matrix scales a point by sx,sy
3.This matrix rotates counterclockwise around the origin