module BioDSL::Math
Adding methods to Math
module.
Public Class Methods
dist_point2line( px, py, x1, y1, x2, y2 )
click to toggle source
Class method to calculate the distance from at point to a line. The point and line are given as pairs of coordinates.
# File lib/BioDSL/math.rb, line 34 def self.dist_point2line( px, # point x coordinate py, # point y coordinate x1, # line 1 x coordinate y1, # line 1 y coordinate x2, # line 2 x coordinate y2 # line 2 y coordinate ) a = (y2 - y1).to_f / (x2 - x1).to_f b = y1 - a * x1 (a * px + b - py).abs / ::Math.sqrt(a**2 + 1) end
dist_point2point(x1, y1, x2, y2)
click to toggle source
Class method to calculate the distance between two points given as pairs of coordinates.
# File lib/BioDSL/math.rb, line 51 def self.dist_point2point(x1, y1, x2, y2) ::Math.sqrt((x2.to_f - x1.to_f)**2 + (y2.to_f - y1.to_f)**2) end