This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RamerDouglasPeucker | |
def self.perpendicular_distance(p1, p2, p3) | |
# Measures the shortest distance of p3 from a line drawn between p1 and p2 | |
# https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line | |
numerator = ( | |
p3[0] * (p2[1] - p1[1]) - | |
p3[1] * (p2[0] - p1[0]) + | |
p2[0] * p1[1] - p2[1] * p1[0] | |
).abs |