Module: Math
- Defined in:
- lib/kvg_character_recognition/utils.rb
Class Method Summary collapse
-
.euclidean_distance(p1, p2) ⇒ Object
Add euclidean distance method to ruby Math module This methods calculates the euclidean distance between 2 points Params: - p1, p2: [x, y].
- .manhattan_distance(p1, p2) ⇒ Object
Class Method Details
.euclidean_distance(p1, p2) ⇒ Object
Add euclidean distance method to ruby Math module This methods calculates the euclidean distance between 2 points Params:
-
p1, p2: [x, y]
6 7 8 9 10 11 12 |
# File 'lib/kvg_character_recognition/utils.rb', line 6 def self.euclidean_distance(p1, p2) sum_of_squares = 0 p1.each_with_index do |p1_coord,index| sum_of_squares += (p1_coord - p2[index]) ** 2 end Math.sqrt( sum_of_squares ) end |
.manhattan_distance(p1, p2) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/kvg_character_recognition/utils.rb', line 14 def self.manhattan_distance(p1, p2) sum = 0 p1.each_with_index do |p1_coord,index| sum += (p1_coord - p2[index]).abs end sum end |