Skip to content

Commit

Permalink
Merge pull request #14 from Cambridge-ICCS/impl3
Browse files Browse the repository at this point in the history
Implement `equation_of_line` using SymPy
  • Loading branch information
TomMelt authored Jul 10, 2024
2 parents c947660 + 189b9d3 commit caa0d3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions maths.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from sympy import Line, Point2D
import numpy as np


Expand All @@ -11,10 +12,9 @@ def equation_of_line(a, b):
"""
if np.allclose(a, b):
raise ValueError("Cannot determine a unique line through {a} and {b}.")
x0, y0 = a
x1, y1 = b
line = Line(Point2D(a), Point2D(b))

def f(x, y):
return (x1 - x0) * (y - y0) - (y1 - y0) * (x - x0)
def evaluate(x, y):
return float(line.distance(Point2D((x, y))))

return f
return evaluate
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy
pytest
sympy

0 comments on commit caa0d3a

Please sign in to comment.