I have a class Point
, consisting of a point with x and y coordinates, and I have to write a method that computes and returns the equation of a straight line joi
I think you are making pretty advanced code, but you are making it complicated. Here is a function that can do that:
from decimal import Decimal
def lin_equ(l1, l2):
"""Line encoded as l=(x,y)."""
m = Decimal((l2[1] - l1[1])) / Decimal(l2[0] - l1[0])
c = (l2[1] - (m * l2[0]))
return m, c
# Example Usage:
lin_equ((-40, 30,), (20, 45))
# Result: (Decimal('0.25'), Decimal('40.00'))