Skip to content

Instantly share code, notes, and snippets.

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