Sha256: 6066ffb34bd5d592891c4fcd97c0c51793bea85a4797cc1fa89bbf6c0a207645

Contents?: true

Size: 903 Bytes

Versions: 7

Compression:

Stored size: 903 Bytes

Contents

module Geom
  class Plane
    attr_accessor(:normal)
    def initialize(normal=nil,point=nil)
      if normal && point
        @normal = normal
        @d      = -Number3D.dot(normal,point)
      else
        @normal = Number3D.new
        @d      = 0
      end
    end

    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

    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

    def distance(point)
      p = point.instance_of?(Vertex) ? point.position : point
      Number3D.dot(p,@normal) + @d
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
floorplanner-fml-0.2.1 lib/geom/plane.rb
floorplanner-fml-0.2 lib/geom/plane.rb
fml-0.2.5 lib/geom/plane.rb
fml-0.2.4 lib/geom/plane.rb
fml-0.2.3 lib/geom/plane.rb
fml-0.2.2 lib/geom/plane.rb
fml-0.2.1 lib/geom/plane.rb