Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Corresponding angles solution in 3rd party category for Similar Triangles by Rcp8jzd
import numpy as np
from typing import List, Tuple
Coords = List[Tuple[int, int]]
def angle(a, b, c):
""" Get the angle between three points, at the vertex b.
Works with 2D or 3D points. """
a = np.array(a)
b = np.array(b)
c = np.array(c)
ba = a - b
bc = c - b
cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
return np.arccos(cosine_angle)
def similar_triangles(coords_1: Coords, coords_2: Coords) -> bool:
""" Test if two triangles are similar. They are similar if and only if
corresponding angles have the same measures """
angles1 = {angle(coords_1[i - 2], coords_1[i - 1], coords_1[i]) for i in
range(3)}
angles2 = {angle(coords_2[i - 2], coords_2[i - 1], coords_2[i]) for i in
range(3)}
return angles1 == angles2
March 29, 2020
Comments: