Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Similar Triangles by twilyght
import math
from typing import List, Tuple
Point = Tuple[int, int]
Coords = List[Point]
def distance(p1: Point, p2: Point) -> float:
x1, y1 = p1
x2, y2 = p2
return math.hypot(x2 - x1, y2 - y1)
def sides(coords: Coords) -> Tuple[float, float, float]:
a = distance(coords[0], coords[1])
b = distance(coords[0], coords[2])
c = distance(coords[1], coords[2])
return a, b, c
def similar_triangles(coords_1: Coords, coords_2: Coords) -> bool:
a1, b1, c1 = sorted(sides(coords_1))
a2, b2, c2 = sorted(sides(coords_2))
return math.isclose(a1 / a2, b1 / b2) and math.isclose(b1 / b2, c1 / c2)
June 11, 2020
Comments: