GraphSolver/methods/linear/calcLinear.py
xypnox a1587e73f7 Add calcLinearIntersection method
This method calculates the intersection point between two Lines. This
method returns the coordinates of intersection if there is a unique
point, 0 if there are none, and math.inf if the lines coincide.
2019-10-28 20:04:09 +03:00

31 lines
910 B
Python

import math
class Linear:
def __init__(self, a, c, length):
self.a = a
self.c = c
self.length = length
def calc_linear_line(self):
print([(0 - self.length, self.a * (0 - self.length)), (0 - self.length, self.a * self.length)])
def calcLineaIntersection(self, line):
"""
This function accepts one line of Linear class
and returns the coordinates of intersection between the self and the line passed
If there is no intercept it returns 0
If there are infinite intercepts it return math.inf
If there is one unique intercept it returns a tuple with (x, y)
"""
if self.a == line.a:
if self.c == line.c:
return math.inf
return 0
x = (line.c-self.c)/(self.a - line.a)
y = self.a*(line.c - self.c)/(self.a - line.a) + self.c
return (x, y)