class Geo3d::Plane
Attributes
a[RW]
b[RW]
c[RW]
d[RW]
w[RW]
x[RW]
y[RW]
z[RW]
Public Class Methods
from_point_and_normal(point, normal)
click to toggle source
# File lib/geo3d/plane.rb, line 23 def self.from_point_and_normal point, normal point.w = 0 self.new normal.x, normal.y, normal.z, -point.dot(normal) end
from_points(pv1, pv2, pv3)
click to toggle source
# File lib/geo3d/plane.rb, line 17 def self.from_points pv1, pv2, pv3 edge1 = pv2 - pv1 edge2 = pv3 - pv1 from_point_and_normal pv1, edge1.cross(edge2).normalize end
new(*args)
click to toggle source
# File lib/geo3d/plane.rb, line 9 def initialize *args @a, @b, @c, @d = 0.0, 0.0, 0.0, 0.0 @a = args[0].to_f if args.size > 0 @b = args[1].to_f if args.size > 1 @c = args[2].to_f if args.size > 2 @d = args[3].to_f if args.size > 3 end
Public Instance Methods
!=(vec)
click to toggle source
# File lib/geo3d/plane.rb, line 36 def != vec !(self == vec) end
==(p)
click to toggle source
# File lib/geo3d/plane.rb, line 32 def == p Geo3d::Utils.float_cmp(a, p.a) && Geo3d::Utils.float_cmp(b, p.b) && Geo3d::Utils.float_cmp(c, p.c) && Geo3d::Utils.float_cmp(d, p.d) end
dot(v)
click to toggle source
# File lib/geo3d/plane.rb, line 40 def dot v a * v.x + b * v.y + c * v.z + d * v.w end
line_intersection(line_start, line_end)
click to toggle source
# File lib/geo3d/plane.rb, line 69 def line_intersection line_start, line_end direction = line_end - line_start normal_dot_direction = normal.dot direction if (normal_dot_direction.zero?) nil else temp = (d + normal.dot(line_start)) / normal_dot_direction line_start - direction * temp end end
normal()
click to toggle source
# File lib/geo3d/plane.rb, line 65 def normal Vector.new a, b, c end
normalize()
click to toggle source
# File lib/geo3d/plane.rb, line 59 def normalize p = self.class.new a, b, c, d p.normalize! p end
normalize!()
click to toggle source
# File lib/geo3d/plane.rb, line 44 def normalize! norm = Math.sqrt(a*a + b*b + c*c) if norm.zero? @a = 0 @b = 0 @c = 0 @d = 0 else @a /= norm @b /= norm @c /= norm @d /= norm end end
to_a()
click to toggle source
# File lib/geo3d/plane.rb, line 28 def to_a [a,b,c,d] end
transform(matrix, use_inverse_transpose = true)
click to toggle source
# File lib/geo3d/plane.rb, line 82 def transform matrix, use_inverse_transpose = true matrix = matrix.inverse.transpose if use_inverse_transpose p = self.class.new p.a = dot matrix.row(0) p.b = dot matrix.row(1) p.c = dot matrix.row(2) p.d = dot matrix.row(3) p end