Class: Geom::Plane
- Inherits:
-
Object
- Object
- Geom::Plane
- Defined in:
- lib/geom/plane.rb
Instance Attribute Summary collapse
-
#normal ⇒ Object
Returns the value of attribute normal.
Class Method Summary collapse
Instance Method Summary collapse
- #distance(point) ⇒ Object
-
#initialize(normal = nil, point = nil) ⇒ Plane
constructor
A new instance of Plane.
- #set_three_points(p0, p1, p2) ⇒ Object
Constructor Details
#initialize(normal = nil, point = nil) ⇒ Plane
Returns a new instance of Plane.
4 5 6 7 8 9 10 11 12 |
# File 'lib/geom/plane.rb', line 4 def initialize(normal=nil,point=nil) if normal && point @normal = normal @d = -Number3D.dot(normal,point) else @normal = Number3D.new @d = 0 end end |
Instance Attribute Details
#normal ⇒ Object
Returns the value of attribute normal.
3 4 5 |
# File 'lib/geom/plane.rb', line 3 def normal @normal end |
Class Method Details
.three_points(p0, p1, p2) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/geom/plane.rb', line 14 def self.three_points(p0,p1,p2) plane = Plane.new n0 = p0.instance_of?(Number3D) ? p0 : p0.position n1 = p1.instance_of?(Number3D) ? p1 : p1.position n2 = p2.instance_of?(Number3D) ? p2 : p2.position plane.set_three_points(n0,n1,n2) plane end |
Instance Method Details
#distance(point) ⇒ Object
31 32 33 34 |
# File 'lib/geom/plane.rb', line 31 def distance(point) p = point.instance_of?(Vertex) ? point.position : point Number3D.dot(p,@normal) + @d end |
#set_three_points(p0, p1, p2) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/geom/plane.rb', line 23 def set_three_points(p0,p1,p2) ab = Number3D.sub(p1,p0) ac = Number3D.sub(p2,p0) @normal = Number3D.cross(ab,ac) @normal.normalize @d = -Number3D.dot(@normal,p0) end |