Skip to content

Commit

Permalink
[math] add linear distance between coords function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissimpkins committed Oct 6, 2020
1 parent ababaa0 commit 9891b2e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/pathins/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ def round_point(pt: float) -> int:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~


def linear_distance_between_coordinates(
coord1: Tuple[int, int], coord2: Tuple[int, int]
) -> float:
"""
Returns the linear distance between two sets of
Cartesian coordinate values.
"""
x1, y1 = coord1
x2, y2 = coord2
x_diff_squared = (x2 - x1) ** 2
y_diff_squared = (y2 - y1) ** 2
return math.sqrt(x_diff_squared + y_diff_squared)


def midpoint_between_coordinates(
coord1: Tuple[int, int], coord2: Tuple[int, int]
) -> Tuple[int, int]:
Expand Down

0 comments on commit 9891b2e

Please sign in to comment.