diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-10-15 15:47:29 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-10-15 15:47:29 +0200 |
| commit | ff6f8002c14b6a39146053d6ab15d94588963641 (patch) | |
| tree | 3790e40e471c34f7b35768e3d7aa7090de22b673 | |
| parent | 843d9afdb48f1344bd1ab1473ee39be0cccb23ca (diff) | |
| download | arithmeticbilliard-ff6f8002c14b6a39146053d6ab15d94588963641.tar.gz arithmeticbilliard-ff6f8002c14b6a39146053d6ab15d94588963641.zip | |
added function for computing multiplicities
| -rw-r--r-- | billiard3d.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/billiard3d.py b/billiard3d.py index d77fc1a..b9eb143 100644 --- a/billiard3d.py +++ b/billiard3d.py | |||
| @@ -36,7 +36,7 @@ def get_path(n, sizes, r): | |||
| 36 | path = [r] | 36 | path = [r] |
| 37 | p = r | 37 | p = r |
| 38 | d = [1] * n | 38 | d = [1] * n |
| 39 | steps = 0 | 39 | steps = 1 |
| 40 | while steps < 2*lcm_list(sizes): | 40 | while steps < 2*lcm_list(sizes): |
| 41 | p = [p[i] + d[i] for i in range(n)] | 41 | p = [p[i] + d[i] for i in range(n)] |
| 42 | path.append(p) | 42 | path.append(p) |
| @@ -44,6 +44,46 @@ def get_path(n, sizes, r): | |||
| 44 | d = [d[i] if p[i] % sizes[i] != 0 else -d[i] for i in range(n)] | 44 | d = [d[i] if p[i] % sizes[i] != 0 else -d[i] for i in range(n)] |
| 45 | return path | 45 | return path |
| 46 | 46 | ||
| 47 | def is_double(path): | ||
| 48 | # A path is double if and only at some point the ball bounces on a | ||
| 49 | # corner and bounces back in the opposite direction. This happens if | ||
| 50 | # and only if for some i we have path[i] = path[i+2] | ||
| 51 | for i in range(0, len(path)-2): | ||
| 52 | if path[i] == path[i+2]: | ||
| 53 | return True | ||
| 54 | |||
| 55 | return False | ||
| 56 | |||
| 57 | def print_multiplicities(n, sizes, r): | ||
| 58 | print("") | ||
| 59 | print("Points with multiplicity > 1:") | ||
| 60 | print("") | ||
| 61 | |||
| 62 | d = dict() | ||
| 63 | path = [tuple(x) for x in get_path(n, sizes, r)] | ||
| 64 | |||
| 65 | for point in path: | ||
| 66 | if point in d: | ||
| 67 | d[point] += 1 | ||
| 68 | else: | ||
| 69 | d[point] = 1 | ||
| 70 | |||
| 71 | if is_double(path): | ||
| 72 | for p in d: | ||
| 73 | d[p] //= 2 | ||
| 74 | |||
| 75 | for i in range(2, max(d.values())+1): | ||
| 76 | L = [] | ||
| 77 | for point in d: | ||
| 78 | if d[point] == i: | ||
| 79 | L.append(point) | ||
| 80 | |||
| 81 | if len(L) != 0: | ||
| 82 | print(len(L), "point of multiplicity", i) | ||
| 83 | print(L) | ||
| 84 | print("") | ||
| 85 | |||
| 86 | |||
| 47 | ############################################################################### | 87 | ############################################################################### |
| 48 | # This part is specific for 2d drawings | 88 | # This part is specific for 2d drawings |
| 49 | ############################################################################### | 89 | ############################################################################### |
| @@ -180,14 +220,20 @@ def user_input(): | |||
| 180 | ra = int(input("a-coordinate of r: ")) | 220 | ra = int(input("a-coordinate of r: ")) |
| 181 | rb = int(input("b-coordinate of r: ")) | 221 | rb = int(input("b-coordinate of r: ")) |
| 182 | rc = int(input("c-coordinate of r: ")) | 222 | rc = int(input("c-coordinate of r: ")) |
| 183 | pic = input("Choose p for projections or 3 for 3d (empty = both): ") | 223 | pic = input("Choose p for projections or 3 for 3d (empty = all, one after the other): ") |
| 184 | return [a,b,c], [ra,rb,rc], pic | 224 | return [a,b,c], [ra,rb,rc], pic |
| 185 | 225 | ||
| 226 | ############################################################################### | ||
| 227 | # Main routine below | ||
| 228 | ############################################################################### | ||
| 229 | |||
| 186 | # You can choose to write your input here or to get it interactively | 230 | # You can choose to write your input here or to get it interactively |
| 187 | #sizes, r, pic = [15, 9, 7], [2, 0, 0], "p" | 231 | #sizes, r, pic = [15, 9, 7], [2, 0, 0], "p" |
| 188 | #sizes, r, pic = [2, 3, 4], [0, 0, 0], "3" | 232 | #sizes, r, pic = [2, 3, 4], [0, 0, 0], "3" |
| 189 | sizes, r, pic = user_input() | 233 | sizes, r, pic = user_input() |
| 190 | 234 | ||
| 235 | print_multiplicities(len(sizes), sizes, r) | ||
| 236 | |||
| 191 | if pic == "p": | 237 | if pic == "p": |
| 192 | draw_3d_projections(sizes, r) | 238 | draw_3d_projections(sizes, r) |
| 193 | elif pic == "3": | 239 | elif pic == "3": |
