Created
February 20, 2023 18:35
-
-
Save webdevwilson/d77a488952d24091331e16e4ee0983c3 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
#!/usr/bin/env python3 | |
import math | |
# Poor man's numpy.arange | |
LENGTHS = [] | |
for i in range(1, 32): | |
LENGTHS.extend([i, i+0.5]) | |
# |\ y - from vertex to top | |
# | \ x - from vertex to right | |
# | \ u - from vertex to top of second triangle | |
# | \ v - intersection to left | |
# |y \ | |
# --v-| \ | |
# \ | \ | |
# \ u \ | |
# \|____x___\ | |
# | |
def find_fourths(s1, s2): | |
global i | |
ratio = s1 / s2 | |
angle = math.degrees(math.atan(ratio)) | |
target_angle = 90 - angle | |
fourths = [] | |
for x in LENGTHS: | |
for y in LENGTHS: | |
if (x != s1 and y != s2) and (x != s2 and y != s1) and is_pythagorean_triple(x, y): | |
# now check the angle | |
interior_angle = math.degrees(math.atan(x / y)) | |
diff = abs(interior_angle - target_angle) | |
if diff == 0.0: | |
fourths.append((x, y, target_angle)) | |
return fourths | |
def is_pythagorean_triple(s1, s2): | |
hypotenuse = math.sqrt(math.pow(s1, 2) + math.pow(s2, 2)) | |
diff = abs(hypotenuse - round(hypotenuse)) | |
return diff < 0.005 | |
for side_1 in LENGTHS: | |
for side_2 in LENGTHS: | |
if is_pythagorean_triple(side_1, side_2): | |
result = find_fourths(side_1, side_2) | |
if len(result) > 0: | |
print(f'Found {len(result)} for y: {side_1}, x: {side_2}') | |
for fourth in result: | |
print(f'\tv: {fourth[0]}, u: {fourth[1]}, angle: {fourth[2]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment