Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
compare side length ratio solution in Clear category for Similar Triangles by yoichi
from itertools import combinations
from math import sqrt
from typing import List, Tuple
Coords = List[Tuple[int, int]]
def get_distance(coords):
return sqrt(sum((coords[0][i]-coords[1][i])**2 for i in range(2)))
def get_sides_ratio(vertices):
sides = sorted(map(get_distance, combinations(vertices, 2)))
return (sides[1]/sides[0], sides[2]/sides[0])
def similar_triangles(coords_1: Coords, coords_2: Coords) -> bool:
return get_sides_ratio(coords_1) == get_sides_ratio(coords_2)
Feb. 15, 2020
Comments: