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.
42 43 44 |
# File 'lib/chem/utils/transform.rb', line 42 def initialize m = Matrix.new @m = m end |
Class Method Details
.inverse_x ⇒ Object
89 90 91 92 93 94 |
# File 'lib/chem/utils/transform.rb', line 89 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
96 97 98 99 100 101 |
# File 'lib/chem/utils/transform.rb', line 96 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
103 104 105 106 107 108 |
# File 'lib/chem/utils/transform.rb', line 103 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
68 69 70 71 72 73 |
# File 'lib/chem/utils/transform.rb', line 68 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
75 76 77 78 79 80 |
# File 'lib/chem/utils/transform.rb', line 75 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
82 83 84 85 86 87 |
# File 'lib/chem/utils/transform.rb', line 82 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
61 62 63 64 65 66 |
# File 'lib/chem/utils/transform.rb', line 61 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
54 55 56 57 58 59 |
# File 'lib/chem/utils/transform.rb', line 54 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
46 47 48 |
# File 'lib/chem/utils/transform.rb', line 46 def * (t) @m * t end |
#transform(v) ⇒ Object
50 51 52 |
# File 'lib/chem/utils/transform.rb', line 50 def transform(v) v * @m end |