Class: Math::Line
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#y_end ⇒ Object
readonly
Returns the value of attribute y_end.
-
#y_start ⇒ Object
readonly
Returns the value of attribute y_start.
Attributes inherited from Function
Class Method Summary collapse
-
.from_yaml(yh) ⇒ Object
from_yaml(yaml_hash):.
Instance Method Summary collapse
-
#initialize(ys, ye, xs, xe) ⇒ Line
constructor
Math::Line.new(ystart, yend, xstart, xend):.
- #label ⇒ Object
-
#y(x) ⇒ Object
:doc:.
Methods inherited from Function
Methods included from Mext::Utilities
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
#a ⇒ Object (readonly)
Returns the value of attribute a.
6 7 8 |
# File 'lib/mext/math/line.rb', line 6 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
6 7 8 |
# File 'lib/mext/math/line.rb', line 6 def b @b end |
#y_end ⇒ Object (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_start ⇒ Object (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 |
Class Method Details
.from_yaml(yh) ⇒ Object
from_yaml(yaml_hash):
creates a Math::Line class from a yaml file which must have the relevant fields:
x_start
x_end
y_start
y_end
58 59 60 61 |
# File 'lib/mext/math/line.rb', line 58 def from_yaml(yh) args = [yh['y_start'], yh['y_end'], yh['x_start'], yh['x_end']] new(*args) end |
Instance Method Details
#label ⇒ Object
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 |