Skip to content

Commit caa0d3a

Browse files
authored
Merge pull request #14 from Cambridge-ICCS/impl3
Implement `equation_of_line` using SymPy
2 parents c947660 + 189b9d3 commit caa0d3a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

maths.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from sympy import Line, Point2D
12
import numpy as np
23

34

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

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

20-
return f
20+
return evaluate

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
numpy
22
pytest
3+
sympy

0 commit comments

Comments
 (0)