Class: GeoTriangleExt::LinearFunction
- Inherits:
-
Object
- Object
- GeoTriangleExt::LinearFunction
- Defined in:
- lib/geo_triangle_ext/linear_function.rb
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #intercept ⇒ Object
- #middle_point ⇒ Object
- #orthogonal_intercept ⇒ Object
- #orthogonal_slope ⇒ Object
- #slope ⇒ Object
- #valid? ⇒ Boolean
Instance Attribute Details
#ax ⇒ Object
21 22 23 24 25 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 21 def ax @bax ||= BigDecimal(@ax.to_s) @bax end |
#ay ⇒ Object
27 28 29 30 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 27 def ay @bay ||= BigDecimal(@ay.to_s) @bay end |
#bx ⇒ Object
32 33 34 35 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 32 def bx @bbx ||= BigDecimal(@bx.to_s) @bbx end |
#by ⇒ Object
37 38 39 40 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 37 def by @bby ||= BigDecimal(@by.to_s) @bby end |
Class Method Details
.create(ax, ay, bx, by) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 10 def create(ax, ay, bx, by) lf = self.new lf.ax = ax lf.ay = ay lf.bx = bx lf.by = by lf end |
Instance Method Details
#intercept ⇒ Object
59 60 61 62 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 59 def intercept return unless valid? (ax * by - ay * bx) / (ax - bx) end |
#middle_point ⇒ Object
48 49 50 51 52 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 48 def middle_point x = (ax + bx) / 2.0 y = (ay + by) / 2.0 [x, y] end |
#orthogonal_intercept ⇒ Object
69 70 71 72 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 69 def orthogonal_intercept return unless valid? (ax*ax + ay*ay - bx*bx - by*by) / (2 * (ay - by)) end |
#orthogonal_slope ⇒ Object
64 65 66 67 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 64 def orthogonal_slope return unless valid? (bx - ax) / (ay - by) end |
#slope ⇒ Object
54 55 56 57 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 54 def slope return unless valid? (ay - by) / (ax - bx) end |
#valid? ⇒ Boolean
42 43 44 45 46 |
# File 'lib/geo_triangle_ext/linear_function.rb', line 42 def valid? return false if ax == bx return false if ay == by true end |