class Dieses::Geometry::Equation::Slant
Attributes
intercept[R]
slope[R]
Public Class Methods
new(slope:, intercept:)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 9 def initialize(slope:, intercept:) @slope, @intercept = slope.to_f, intercept.to_f freeze end
Public Instance Methods
angle_in_radian()
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 39 def angle_in_radian Math.atan(slope) end
eql?(other)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 68 def eql?(other) self.class == other.class && to_h == other.to_h end
Also aliased as: ==
hash()
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 74 def hash self.class.hash ^ to_h.hash end
intersect(other)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 43 def intersect(other) case other when Slant x = (other.intercept - intercept) / (slope - other.slope) y = slope * x + intercept when Steep x = other.x y = y(x) end Point.new(x, y) end
left?(point, precision: Support::Float.precision)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 56 def left?(point, precision: Support::Float.precision) Support.almost_greater_than(point.y, y(point.x), precision: precision) end
onto?(point, precision: Support::Float.precision)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 64 def onto?(point, precision: Support::Float.precision) Support.almost_equal(point.y, y(point.x), precision: precision) end
right?(point, precision: Support::Float.precision)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 60 def right?(point, precision: Support::Float.precision) Support.almost_less_than(point.y, y(point.x), precision: precision) end
to_h()
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 78 def to_h { slope: scope, intercept: intercept } end
to_s()
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 82 def to_s "E(y = #{slope} * x + #{intercept})" end
translate(distance = nil, x: nil, y: nil)
click to toggle source
When distance given, y = m * x + n (m, n positive) equation moves to the right (x increases, y decreases)
# File lib/dieses/geometry/equation/slant.rb, line 23 def translate(distance = nil, x: nil, y: nil) dx, dy = 0, 0 intercept = self.intercept dx, dy = distance * Math.cos(angle_in_radian), -distance * Math.sin(angle_in_radian) if distance dx += x if x dy += y if y intercept -= slope * dx intercept += dy self.class.new slope: slope, intercept: intercept end
x(y)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 14 def x(y) (y - intercept) / slope end
y(x)
click to toggle source
# File lib/dieses/geometry/equation/slant.rb, line 18 def y(x) slope * x + intercept end