Class: GMath3D::Plane

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

Overview

Plane represents a infinite plane on 3D space.

Instance Attribute Summary collapse

Attributes inherited from Geom

#tolerance

Instance Method Summary collapse

Methods inherited from Geom

default_tolerance

Constructor Details

#initialize(base_point = Vector3.new(), normal = Vector3.new(0,0,1)) ⇒ Plane

Input

base_point and normal should be Vector3.

Output

returns new instance of Plane.



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

def initialize(base_point = Vector3.new(), normal = Vector3.new(0,0,1))
  Util3D.check_arg_type(::Vector3, normal)
  Util3D.check_arg_type(::Vector3, base_point)
  super()
  @base_point = base_point
  @normal = normal.normalize()
end

Instance Attribute Details

#base_pointObject

Returns the value of attribute base_point.



8
9
10
# File 'lib/plane.rb', line 8

def base_point
  @base_point
end

#normalObject

Returns the value of attribute normal.



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

def normal
  @normal
end

Instance Method Details

#==(rhs) ⇒ Object

Input

rhs is Plane.

Output

return true if rhs equals myself.



32
33
34
35
36
37
38
# File 'lib/plane.rb', line 32

def ==(rhs)
  return false if rhs == nil
  return false if( !rhs.kind_of?(Plane) )
  return false if( self.base_point != rhs.base_point)
  return false if( self.normal != rhs.normal)
  return true
end

#distance(target) ⇒ Object

This function returns closest distance between Line and anothor element.

Input

target should be Vector3 or Line or FiniteLine or Plane.

Output
in case target is Vector3

return “distance, closest point on myself” as [Numeric, Vector3].

in case target is Line

return “distance, intersect point, parameter on tatget” as [Numeric, Vector3, Numeric].

in case target is FiniteLine

return “distance, point on plane, point on target, parameter on target” as [Numeric, Vector3, Vector3, Numeric].

in case target is Plane

return “distance, intersect line” as [Numeric, Vector3].



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/plane.rb', line 58

def distance(target)
  # with Point
  if(target.kind_of?(Vector3))
    return distance_to_point(target)
  #with Line
  elsif(target.kind_of?(Line))
    return distance_to_line(target)
  #with FiniteLine
  elsif(target.kind_of?(FiniteLine))
    return distance_to_finite_line(target)
  #with Plane
  elsif(target.kind_of?(Plane))
    return distance_to_plane(target)
  end
  Util3D.raise_argurment_error(target)
end

#initialize_copy(original_obj) ⇒ Object



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

def initialize_copy( original_obj )
  @base_point = original_obj.base_point.dup
  @normal = original_obj.normal.dup
end

#project(target_point) ⇒ Object

Input

target_point should be Vector3.

Output

retrun projected point on plane as Vector3.



79
80
81
82
83
# File 'lib/plane.rb', line 79

def project( target_point )
  Util3D.check_arg_type(::Vector3, target_point)
  distance, closest_point = self.distance( target_point )
  return closest_point
end

#to_sObject



40
41
42
# File 'lib/plane.rb', line 40

def to_s
  "Plane[point#{@base_point.to_element_s}, normal#{@normal.to_element_s}]"
end