imk0tter

ROTATIX_LIBRARY - Python

Mar 21st, 2022 (edited)
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. import math
  2.  
  3. def gcd(*numbers):
  4.     a = numbers[0]
  5.     if len(numbers) <= 1:
  6.         return a
  7.     b = numbers[1]
  8.     current = a % b
  9.     next_numbers = []
  10.     next_numbers.extend(numbers[2:])
  11.  
  12.     if current != 0:
  13.         return gcd(b, current, *tuple(next_numbers))
  14.     return gcd(b, *tuple(next_numbers))
  15.  
  16.  
  17. def lcm(*numbers):
  18.     if len(numbers) > 1:
  19.         temp = list(numbers[2:])
  20.         return lcm(numbers[0] * numbers[1] / gcd(numbers[0], numbers[1]), *tuple(temp))
  21.     return numbers[0]
  22.  
  23. def sides_and_rotations_to_degrees_per_radian_and_degrees(degrees_per_rotation, *rotations):
  24.     degrees_per_radian = degrees_per_rotation / (math.pi * 2)
  25.     degrees = []
  26.     for x in range(0, len(rotations)):
  27.         degrees.append(rotations[x])
  28.     return (degrees_per_radian, tuple(degrees))
  29.  
  30. def degrees_per_radian_and_degrees_per_iteration_to_radians_per_iteration(degrees_per_radian, *degrees_per_iteration):
  31.     radians_per_iteration = []
  32.  
  33.     for x in range(0, len(degrees_per_iteration)):
  34.         radians_per_iteration.append(degrees_per_iteration[x] / degrees_per_radian)
  35.     return tuple(radians_per_iteration)
  36.  
  37. def rectify_degrees_per_radian_and_degrees_per_iteration(degrees_per_radian, *degrees_per_iteration):
  38.     divider = gcd(*degrees_per_iteration)
  39.  
  40.     degrees_per_radian /= divider
  41.     degrees_per_iteration_ = []
  42.     for x in range(0, len(degrees_per_iteration)):
  43.         degrees_per_iteration_.append(math.trunc(degrees_per_iteration[x] / divider))
  44.  
  45.     return (degrees_per_radian, tuple(degrees_per_iteration_))
  46.  
  47. # entry point
  48. sides = 50
  49. rotations = (1.5, 3, 7)
  50.  
  51. print("Sides: " + str(sides))
  52. print("Rotations: " + str(rotations))
  53. print("")
  54.  
  55. result = sides_and_rotations_to_degrees_per_radian_and_degrees(sides, *rotations)
  56.  
  57. print("degrees_per_radian: " + str(result[0]))
  58. print("degrees_per_iteration: " + str(result[1]))
  59. radians_per_iteration = degrees_per_radian_and_degrees_per_iteration_to_radians_per_iteration(result[0], *result[1])
  60. print("radians_per_iteration: " + str(radians_per_iteration))
  61. print("")
  62.  
  63. result = rectify_degrees_per_radian_and_degrees_per_iteration(result[0], *result[1])
  64. print("degrees_per_radian_rectified: " + str(result[0]))
  65. print("degrees_per_iteration_rectified: " + str(result[1]))
  66. radians_per_iteration = degrees_per_radian_and_degrees_per_iteration_to_radians_per_iteration(result[0], *result[1])
  67. print("radians_per_iteration_rectified: " + str(radians_per_iteration))
  68.  
Add Comment
Please, Sign In to add comment