Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Similar Triangles solution in Clear category for Similar Triangles by JimmyCarlos
from math import acos,hypot
def cosine_rule(a,b,c) -> float:
"""Find the size of angle opposite to line a, in radians."""
return acos((b**2+c**2-a**2)/(2*b*c))
def similar_triangles(A,B) -> bool:
# Similar Triangles = All angles the same, so let's just find all the angles.
pythagoras=lambda x,y:hypot(x[0]-y[0],x[1]-y[1])
a,b,c = pythagoras(A[0],A[1]),pythagoras(A[0],A[2]),pythagoras(A[1],A[2])
A_angles = sorted([cosine_rule(a,b,c),cosine_rule(b,a,c),cosine_rule(c,a,b)])
a,b,c = pythagoras(B[0],B[1]),pythagoras(B[0],B[2]),pythagoras(B[1],B[2])
B_angles = sorted([cosine_rule(a,b,c),cosine_rule(b,a,c),cosine_rule(c,a,b)])
return A_angles == B_angles
Feb. 13, 2020