Class: GMath3D::Line

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

Overview

Line represents a infinite line 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(point = Vector3.new(0.0,0.0,0.0), direction = Vector3.new(1.0,0.0,0.0)) ⇒ Line

Input

point and direction should be Vector3.

Output

return new instance of Line.



20
21
22
23
24
25
26
# File 'lib/line.rb', line 20

def initialize(point = Vector3.new(0.0,0.0,0.0), direction = Vector3.new(1.0,0.0,0.0))
  Util3D.check_arg_type(Vector3, point)
  Util3D.check_arg_type(Vector3, direction)
  super()
  @base_point = point
  @direction  = direction
end

Instance Attribute Details

#base_pointObject

Returns the value of attribute base_point.



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

def base_point
  @base_point
end

#directionObject

Returns the value of attribute direction.



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

def direction
  @direction
end

Instance Method Details

#==(rhs) ⇒ Object

Input

rhs is Line.

Output

return true if rhs equals myself.



37
38
39
40
41
42
43
# File 'lib/line.rb', line 37

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

#distance(target) ⇒ Object

This function returns closest distance between Line and anothor element.

Input

target should be Vector3 or Line.

Output
in case target is Vector3

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

in case target is Line

return “distance, point on myself, point on target, parameter on myself, parameter on tatget” as [Numeric, Vector3, Vector3, Numeric, Numeric]



64
65
66
67
68
69
70
71
72
73
# File 'lib/line.rb', line 64

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)
  end
  Util3D.raise_argurment_error(target)
end

#initialize_copy(original_obj) ⇒ Object



28
29
30
31
# File 'lib/line.rb', line 28

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

#point(parameter) ⇒ Object

Input

parameter should be Numeric.

Output

return a point on line at input parameter position as Vector3



49
50
51
52
# File 'lib/line.rb', line 49

def point(parameter)
  Util3D.check_arg_type(::Numeric, parameter)
  @base_point + @direction*parameter
end

#to_sObject



12
13
14
# File 'lib/line.rb', line 12

def to_s
  "Line[point#{@base_point.to_element_s}, vector#{@direction.to_element_s}"
end