Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
integer math only solution in Clear category for Similar Triangles by juestr
from itertools import combinations, starmap
from typing import List, Tuple
Coords = List[Tuple[int, int]]
def similar_triangles(coords_1: Coords, coords_2: Coords) -> bool:
def dist(p1, p2):
x1, y1, x2, y2 = *p1, *p2
return (x1 - x2)**2 + (y1 - y2)**2
a1, b1, c1 = sorted(starmap(dist, combinations(coords_1, 2)))
a2, b2, c2 = sorted(starmap(dist, combinations(coords_2, 2)))
return (a1*a2, b1*a2, c1*a2) == (a2*a1, b2*a1, c2*a1)
Feb. 13, 2020