Class: Transform

Inherits:
Object
  • Object
show all
Defined in:
lib/chem/utils/transform.rb

Class Method Summary collapse

Instance Method Summary collapse

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_xObject



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_yObject



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_zObject



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