Created
February 15, 2018 08:18
-
-
Save MrMeison/379d5eee4bb259590832088abbd388d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_length_square(p1, p2): | |
return (p1[0]-p2[0])**2 + (p1[1] - p2[1])**2 | |
def check_angle(p1, p2, p3): | |
return get_length_square(p1, p3) == get_length_square(p1, p2) + get_length_square(p2, p3) | |
def count_right_angles(coords): | |
count = 0 | |
if check_angle(coords[0],coords[1],coords[2]): | |
count = count + 1 | |
if check_angle(coords[1],coords[2],coords[3]): | |
count = count + 1 | |
if check_angle(coords[2],coords[3],coords[0]): | |
count = count + 1 | |
if check_angle(coords[3],coords[0],coords[1]): | |
count = count + 1 | |
return count | |
if __name__ == '__main__': | |
test_data = [[-1, 0], [-1, 4], [2, 4], [4, 1]] | |
print(count_right_angles(test_data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment