Module: Aims::Vectorize

Included in:
Geometry, Plane, Volume, ZincBlende
Defined in:
lib/aims/vectorize.rb

Instance Method Summary collapse

Instance Method Details

#cross(b, c) ⇒ Object

Cross product of two arrays of length 3



15
16
17
18
19
20
# File 'lib/aims/vectorize.rb', line 15

def cross(b,c)
  unless b.size == 3 and c.size == 3
    raise "Vectors must be of length 3"
  end
  Vector[b[1]*c[2] - b[2]*c[1], b[2]*c[0] - b[0]*c[2], b[0]*c[1] - b[1]*c[0]]
end

#dot(a, b) ⇒ Object

Dot product of two n-element arrays



5
6
7
8
9
10
11
12
# File 'lib/aims/vectorize.rb', line 5

def dot(a, b)
  unless a.size == b.size
    raise "Vectors must be the same length"
  end
  
  # Make element-by-element array of pairs
  (a.to_a).zip(b.to_a).inject(0) {|tot, pair| tot = tot + pair[0]*pair[1]}
end