This matrix rotates counterclockwise around the origin : matrix « Number « Ruby






This matrix rotates counterclockwise around the origin


require "matrix"
unit = 2

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

 








Related examples in the same category

1.matrix in action
2.This matrix scales a point by sx,sy
3.Two transformations in one