Created
August 2, 2020 16:24
-
-
Save yuwash/6591247418639cabf4b1b7ef3d831a08 to your computer and use it in GitHub Desktop.
Find best-fit of tessarating two paper formats on each others
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
from itertools import product | |
dumplings = (352, 175) # Kartoffel Knödel 4000400130570 | |
a5 = (210, 148) | |
def min_mod(x1, x2, n1_max): | |
def mod_for_n1(n1): | |
return (x1*n1) % x2 | |
return min((mod_for_n1(n1), n1) for n1 in range(1, n1_max)) | |
def min_mod_area(x1, y1, x2, y2, n1_max, m1_max): | |
def mod_area_for_n1_m2(n1, m1): | |
x_mod = (n1*x1) % x2 | |
y_mod = (m1*y1) % y2 | |
return x_mod*m1*y1 + y_mod*(n1*x1 - x_mod) | |
return min( | |
(mod_area_for_n1_m2(n1, m1), n1, m1) | |
for n1, m1 in product(range(1, n1_max), range(1, m1_max))) | |
def get_x_y(format_, orientation): | |
if orientation: | |
return format_[1], format_[0] | |
return format_ | |
if __name__ == '__main__': | |
for format1, format2 in [(dumplings, a5), (a5, dumplings)]: | |
print(format1, format2) | |
for orientation1, orientation2 in product((0, 1), (0, 1)): | |
x1, y1 = get_x_y(format1, orientation1) | |
x2, y2 = get_x_y(format2, orientation2) | |
print(orientation1, orientation2, min_mod(x1, x2, 15)) | |
print(min_mod_area(x1, y1, x2, y2, 15, 15)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment