Sha256: e96a4b5e28369d86e364279e2340a7f480abaff3d9d683f68cbf9788d314fe96
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
# coding: utf-8 module GeoTriangleExt class LinearFunction attr_writer :ax, :ay, :bx, :by class << self def create(ax, ay, bx, by) lf = self.new lf.ax = ax lf.ay = ay lf.bx = bx lf.by = by lf end end def ax @bax ||= BigDecimal(@ax.to_s) @bax end def ay @bay ||= BigDecimal(@ay.to_s) @bay end def bx @bbx ||= BigDecimal(@bx.to_s) @bbx end def by @bby ||= BigDecimal(@by.to_s) @bby end def valid? return false if ax == bx return false if ay == by true end def middle_point x = (ax + bx) / 2.0 y = (ay + by) / 2.0 [x, y] end def slope return unless valid? (ay - by) / (ax - bx) end def intercept return unless valid? (ax * by - ay * bx) / (ax - bx) end def orthogonal_slope return unless valid? (bx - ax) / (ay - by) end def orthogonal_intercept return unless valid? (ax*ax + ay*ay - bx*bx - by*by) / (2 * (ay - by)) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
geo-triangle-0.0.1 | lib/geo_triangle_ext/linear_function.rb |