Class: Surface

Inherits:
Object show all
Defined in:
lib/lib/surface/surface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(v, p, tol = 0) ⇒ Surface

Returns a new instance of Surface.



4
5
6
7
8
# File 'lib/lib/surface/surface.rb', line 4

def initialize v, p, tol = 0
  @normal = v.to_v || nil
  @p = p.to_v || Vector[0,0,0]
  @tol = tol
end

Instance Attribute Details

#normalObject

Returns the value of attribute normal.



3
4
5
# File 'lib/lib/surface/surface.rb', line 3

def normal
  @normal
end

#pObject

Returns the value of attribute p.



3
4
5
# File 'lib/lib/surface/surface.rb', line 3

def p
  @p
end

#tolObject

Returns the value of attribute tol.



2
3
4
# File 'lib/lib/surface/surface.rb', line 2

def tol
  @tol
end

Instance Method Details

#above?(p, tol = @tol) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/lib/surface/surface.rb', line 11

def above? p, tol = @tol
  dist(p) + tol < 0
end

#below?(p, tol = @tol) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/lib/surface/surface.rb', line 14

def below? p, tol = @tol
  dist(p) - tol > 0
end

#dist(p) ⇒ Object



20
21
22
23
# File 'lib/lib/surface/surface.rb', line 20

def dist p
  p = p.pos if p.is_a? Atom
  (p.to_v- @p).to_a * @normal / @normal.magnitude
end

#include?(p, tol = @tol) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/lib/surface/surface.rb', line 17

def include? p, tol = @tol
  dist(p).abs <= tol
end

#move!(v) ⇒ Object



27
28
29
# File 'lib/lib/surface/surface.rb', line 27

def move! v
  @p += v.to_v
end

#rotate!(d, o, a) ⇒ Object



24
25
26
# File 'lib/lib/surface/surface.rb', line 24

def rotate! d,o,a
  @normal = @normal.rotate!(d.to_v,o.to_v,a)
end