Class: TMatrix
- Inherits:
-
Matrix
- Object
- Matrix
- TMatrix
- Defined in:
- lib/transformatrix.rb
Class Method Summary collapse
-
.reflection(lx, ly) ⇒ Object
Create matrix for reflecting about a line interpolating (0,0) and (lx,ly).
-
.rotation(alpha) ⇒ Object
Create matrix for rotating alpha radians about origo.
-
.scaling(sx, sy) ⇒ Object
Create matrix for scaling relative to origo.
-
.translation(tx, ty) ⇒ Object
Create matrix for translating by [tx, ty].
Instance Method Summary collapse
-
#*(arg) ⇒ Object
Multiplication with 2D vector or array.
Class Method Details
.reflection(lx, ly) ⇒ Object
Create matrix for reflecting about a line interpolating (0,0) and (lx,ly)
54 55 56 57 58 59 |
# File 'lib/transformatrix.rb', line 54 def self.reflection lx, ly rows [\ [lx**2-ly**2, 2*lx*ly, 0 ],\ [2*lx*ly, ly**2-lx**2, 0 ],\ [0, 0, lx**2+ly**2 ]] end |
.rotation(alpha) ⇒ Object
Create matrix for rotating alpha radians about origo
38 39 40 41 42 43 |
# File 'lib/transformatrix.rb', line 38 def self.rotation alpha rows [ \ [Math::cos(alpha), Math::sin(alpha), 0], \ [-Math::sin(alpha), Math::cos(alpha), 0], \ [0, 0, 1]] end |
.scaling(sx, sy) ⇒ Object
Create matrix for scaling relative to origo
62 63 64 65 66 67 |
# File 'lib/transformatrix.rb', line 62 def self.scaling sx, sy rows [\ [sx, 0, 0],\ [0, sy, 0],\ [0, 0, 1]] end |
.translation(tx, ty) ⇒ Object
Create matrix for translating by [tx, ty]
46 47 48 49 50 51 |
# File 'lib/transformatrix.rb', line 46 def self.translation tx, ty rows [\ [1, 0, tx ],\ [0, 1, ty ],\ [0, 0, 1 ]] end |
Instance Method Details
#*(arg) ⇒ Object
Multiplication with 2D vector or array
7 8 9 10 11 12 13 14 15 |
# File 'lib/transformatrix.rb', line 7 def * arg if arg.is_a? Array multiply_array arg elsif arg.is_a? Vector Vector.elements multiply_array(arg.to_a) else super.* arg end end |