Class: Math::Line

Inherits:
Function show all
Defined in:
lib/mext/math/line.rb

Instance Attribute Summary collapse

Attributes inherited from Function

#x_end, #x_start

Instance Method Summary collapse

Methods inherited from Function

#xy

Constructor Details

#initialize(ys, ye, xs, xe) ⇒ Line

Math::Line.new(ystart, yend, xstart, xend):

linear interpolation ‘y = a*x + b` where:

‘a = (yend-ystart)/(xend-xstart)` `b = ystart - (a*xstart)`

Arguments are:

ystart, yend: start/end y values required xstart, xend: start/end x values

:nodoc:



22
23
24
25
26
27
28
# File 'lib/mext/math/line.rb', line 22

def initialize(ys, ye, xs, xe)
  @y_start = ys.to_f
  @y_end   = ye.to_f
  @x_start = xs.to_f
  @x_end   = xe.to_f
  setup
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a.



6
7
8
# File 'lib/mext/math/line.rb', line 6

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b.



6
7
8
# File 'lib/mext/math/line.rb', line 6

def b
  @b
end

#y_endObject (readonly)

Returns the value of attribute y_end.



5
6
7
# File 'lib/mext/math/line.rb', line 5

def y_end
  @y_end
end

#y_startObject (readonly)

Returns the value of attribute y_start.



5
6
7
# File 'lib/mext/math/line.rb', line 5

def y_start
  @y_start
end

Instance Method Details

#labelObject



41
42
43
# File 'lib/mext/math/line.rb', line 41

def label
  "a: #{self.a}\nb: #{self.b}"
end

#y(x) ⇒ Object

:doc:

y(x):

Returns a real value given x

:nodoc:



37
38
39
# File 'lib/mext/math/line.rb', line 37

def y(x)
  (self.a*x) + self.b
end