Class: Transform
- Inherits:
-
Object
- Object
- Transform
- Defined in:
- lib/chem/utils/transform.rb
Class Method Summary collapse
- .inverse_x ⇒ Object
- .inverse_y ⇒ Object
- .inverse_z ⇒ Object
- .rotate_x(theta) ⇒ Object
- .rotate_y(theta) ⇒ Object
- .rotate_z(theta) ⇒ Object
- .scale(x, y, z) ⇒ Object
- .translate(x, y, z) ⇒ Object
Instance Method Summary collapse
- #*(t) ⇒ Object
-
#initialize(m = Matrix.new) ⇒ Transform
constructor
A new instance of Transform.
- #transform(v) ⇒ Object
Constructor Details
#initialize(m = Matrix.new) ⇒ Transform
Returns a new instance of Transform.
41 42 43 |
# File 'lib/chem/utils/transform.rb', line 41 def initialize m = Matrix.new @m = m end |
Class Method Details
.inverse_x ⇒ Object
88 89 90 91 92 93 |
# File 'lib/chem/utils/transform.rb', line 88 def Transform::inverse_x Matrix[[ -1, 0, 0, 0], [ 0, 1, 0, 0], [ 0, 0, -1, 0], [ 0, 0, 0, 1]].transpose end |
.inverse_y ⇒ Object
95 96 97 98 99 100 |
# File 'lib/chem/utils/transform.rb', line 95 def Transform::inverse_y Matrix[[ 1, 0, 0, 0], [ 0, -1, 0, 0], [ 0, 0, 1, 0], [ 0, 0, 0, 1]].transpose end |
.inverse_z ⇒ Object
102 103 104 105 106 107 |
# File 'lib/chem/utils/transform.rb', line 102 def Transform::inverse_z Matrix[[ 1, 0, 0, 0], [ 0, 1, 0, 0], [ 0, 0, -1, 0], [ 0, 0, 0, 1]].transpose end |
.rotate_x(theta) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/chem/utils/transform.rb', line 67 def Transform::rotate_x(theta) Matrix[[1.0, 0.0, 0.0, 0.0], [0.0, Math.cos(theta), Math.sin(theta), 0.0], [0.0, - Math.sin(theta), Math.cos(theta), 0.0], [0.0, 0.0, 0.0, 1.0]].transpose end |
.rotate_y(theta) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/chem/utils/transform.rb', line 74 def Transform::rotate_y(theta) Matrix[[Math.cos(theta), 0.0, - Math.sin(theta), 0.0], [0.0, 1.0, 0.0, 0.0], [Math.sin(theta), 0.0, Math.cos(theta), 0.0], [0.0, 0.0, 0.0, 1.0]].transpose end |
.rotate_z(theta) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/chem/utils/transform.rb', line 81 def Transform::rotate_z(theta) Matrix[[ Math.cos(theta), Math.sin(theta), 0.0, 0.0], [- Math.sin(theta), Math.cos(theta), 0.0, 0.0], [ 0.0, 0.0, 1.0, 0.0], [ 0.0, 0.0, 0.0, 1.0]].transpose end |
.scale(x, y, z) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/chem/utils/transform.rb', line 60 def Transform::scale(x, y, z) Matrix[[x, 0, 0, 0], [0, y, 0, 0], [0, 0, z, 0], [0, 0, 0, 1]].transpose end |
.translate(x, y, z) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/chem/utils/transform.rb', line 53 def Transform::translate(x, y, z) Matrix[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [x, y, z, 1]].transpose end |
Instance Method Details
#*(t) ⇒ Object
45 46 47 |
# File 'lib/chem/utils/transform.rb', line 45 def * (t) @m * t end |
#transform(v) ⇒ Object
49 50 51 |
# File 'lib/chem/utils/transform.rb', line 49 def transform(v) v * @m end |