import sympy.functions as sym
import sympy.geometry as geo
sqrt = sym.sqrt
def distance(A, B):
"""
A & B are objects with x and y attributes
:return: the distance between A and B
"""
dx = B.x - A.x
dy = B.y - A.y
return sqrt(dx**2 + dy**2)
def sides(A, B, C):
"""
A, B & C are objects with x and y attributes
:return: sorted side lengths (smallest to largest)
"""
a = distance(B, C)
b = distance(A, C)
c = distance(A, B)
return sorted((a, b, c,), key=float)
def area(a, b, c):
"""
a, b & c are the side lengths of the trigon
:return: area of the trigon
"""
p = a + b + c # perimeter
sp = p / 2 # semi-perimeter
return sqrt(sp*(sp-a)*(sp-b)*(sp-c))
if __name__ == '__main__':
p = geo.Point
A = p(0, 0)
B = p(3, 0)
C = p(3, 3)
sides = sides(A,B,C)
print(sides)
print(area(*sides))