Class: EpiMath::Line

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(point, vector) ⇒ Line

Parameters:

point

Any point on the line. It must be a Point (../point/point.class.rb)

vector

Any vector director of the line. It must be a Vector (../vector/vector.class.rb)



16
17
18
19
20
21
22
23
24
# File 'lib/epimath100/line.class.rb', line 16

def initialize point, vector
  Error.call "Line::new : '#{point}' is not a Point" if !point.is_a?Point
  Error.call "Line::new : '#{vector}' is not a Vector" if !vector.is_a?Vector
  Error.call "Line::new : '#{vector}' can't be Null" if vector.nil?

  @point = point
  @v_dir = vector
  @equ_para = Line::parametric @point, @v_dir
end

Instance Attribute Details

#equ_paraObject (readonly)

Returns the value of attribute equ_para.



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

def equ_para
  @equ_para
end

#pointObject (readonly)

Returns the value of attribute point.



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

def point
  @point
end

#v_dirObject (readonly)

Returns the value of attribute v_dir.



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

def v_dir
  @v_dir
end

Class Method Details

.parametric(point, v_dir) ⇒ Object

Parameters:

point

point is a Point on the line

v_dir

a vector director of the line

Returns:

Hash



74
75
76
77
78
79
80
81
82
# File 'lib/epimath100/line.class.rb', line 74

def self.parametric point, v_dir
  Error.call "Line::parametric : Invalid vector" if !v_dir.is_a?Vector
  Error.call "Line::parametric : Invalid point" if !point.is_a?Point

  þ = 1
  { :x => { :p => point.x, :v => þ * v_dir.x},
    :y => { :p => point.y, :v => þ * v_dir.y},
    :z => { :p => point.z, :v => þ * v_dir.z}}
end

Instance Method Details

#function(v) ⇒ Object

This function returns the point on the line where x = v * vx + px, …

Parameters:

v

The value defined the point wich will be return.

Returns:

The choosed Point one the line from v (lambda)



98
99
100
101
102
103
104
# File 'lib/epimath100/line.class.rb', line 98

def function v
  Error.call "Line::function : unable to execute function : the vector v_dir is null" if self.nil?
  Error.call "Line::functionx : invalid lambda ( #{v} ) value" if !v.is_a?Numeric

  lp = parametric()
  Point.new(lp[:x][:p] + v * lp[:x][:v], lp[:y][:p] + v * lp[:y][:v], lp[:z][:p] + v * lp[:z][:v])
end

#parametricObject

Returns::

same than self.parametric but with the current object


63
64
65
# File 'lib/epimath100/line.class.rb', line 63

def parametric
  return Line::parametric @point, @v_dir
end

#point_owned?(p) ⇒ Boolean

TODO : fix if if if if if Check if the point specified is ON the line

Parameter:

p

p is a Point

Returns:

true/false

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/epimath100/line.class.rb', line 33

def point_owned? p
  Error.call "Line::point_owned? : #{p} is not a valid Point" if !p.is_a?Point

  l = parametric()

  ux = (p.x - l[:x][:p]) / l[:x][:v]
  uy = (p.y - l[:y][:p]) / l[:y][:v]
  uz = (p.z - l[:z][:p]) / l[:z][:v]

  if l[:x][:v] == 0 and p.x == l[:x][:p]
    ux = uy
  end

  if l[:y][:v] == 0 and p.y == l[:y][:p]
    uy = uz
  end

  if l[:z][:v] == 0 and p.z == l[:z][:p]
    uz = ux
  end

  if ux == uy and ux == uz
    true
  else
    false
  end
end

#to_s(options = {}) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/epimath100/line.class.rb', line 84

def to_s(options={})
  if options == {}
    "droite passant par le point (#{@point.x};#{@point.y};#{@point.z}), de vecteur directeur #{@v_dir.to_s}"
  else
    Error.call "Line::to_s : options is not valid"
  end
end