Class: Aims::Plane

Inherits:
Object
  • Object
show all
Defined in:
lib/aims/plane.rb

Overview

A Class representing a plane. Internally stored in Hessian Normal Form. 0 = Ax + By + Cz - D

(A,B,C) is the plane normal. D is the distance from the origin.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, c, x = 0, y = 0, z = 0) ⇒ Plane

Initialize this plane with the normal (a,b,c) and a point (x,y,z) on the plane



14
15
16
17
18
19
20
21
22
# File 'lib/aims/plane.rb', line 14

def initialize(a, b, c, x=0, y=0, z=0)
  @a = a
  @b = b
  @c = c
  if (@a == 0 and @b == 0 and @c == 0)
    raise "Invalid definition of plane."
  end
  @d = a*x + b*y + c*z
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a.



10
11
12
# File 'lib/aims/plane.rb', line 10

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b.



10
11
12
# File 'lib/aims/plane.rb', line 10

def b
  @b
end

#cObject (readonly)

Returns the value of attribute c.



10
11
12
# File 'lib/aims/plane.rb', line 10

def c
  @c
end

#dObject (readonly)

Returns the value of attribute d.



10
11
12
# File 'lib/aims/plane.rb', line 10

def d
  @d
end

Instance Method Details

#==(aPlane) ⇒ Object Also known as: eql?

Two planes are equal if there ABCD parameters are equal



68
69
70
# File 'lib/aims/plane.rb', line 68

def ==(aPlane)
  @a == aPlane.a and @b == aPlane.b and @c == aPlane.c and @d == aPlane.d
end

#any_point_on_planeObject

return some arbitrary point on the plane



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aims/plane.rb', line 25

def any_point_on_plane
  
  unless (@c == 0)
    return Vector[0, 0, @d/@c]
  end
  
  unless (@b == 0)
    return Vector[0, @d/@b, 0]
  end
  
  unless (@a == 0)
    return Vector[@d/@a, 0, 0]
  end
  
  # Actually if we get to this point, the plane undetermined and all of R3 satisfies the definition
  return Vector[0,0,0]
end

#displace_along_normal(distance) ⇒ Object

Displace this plane a distance in the direction of its normal



63
64
65
# File 'lib/aims/plane.rb', line 63

def displace_along_normal(distance)
  @d += distance
end

#distance_to_point(x, y, z) ⇒ Object

Return the distance to point (x,y,z)

distance = D - Ax - By - Cz



46
47
48
# File 'lib/aims/plane.rb', line 46

def distance_to_point(x, y, z)
  a*x + b*y + c*z - d
end

#intersection_with_ray(a, b) ⇒ Object

The equation for the interstion of a ray and a plane NOT YET IMPLEMENTED



58
59
60
# File 'lib/aims/plane.rb', line 58

def intersection_with_ray(a, b)
  raise "Sorry. Plane#intersection_with_ray is not yet implemented"
end

#unit_normalObject

Return the unit normal Vector[a, b, c]



51
52
53
54
# File 'lib/aims/plane.rb', line 51

def unit_normal
  v = Vector[@a, @b, @c]
  v*(1/v.r)
end