-
Notifications
You must be signed in to change notification settings - Fork 0
/
irrationals.py
49 lines (36 loc) · 1.34 KB
/
irrationals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
GOLDEN RATIO
============
This file holds an interesting visual proof of how some constans are irrational.
"""
from math import sqrt, cos, sin, radians, pi
PHI = (1 + sqrt(5)) / 2
PI = pi
def irrationalProof(maximum, constant = PHI):
"""
Visual proof of constant's irrationality. Over a large enough number of iterations, an interesting pattern appears.
"""
# Initial positions and angles
x1, y1 = 0, 0 # First arm starting at the origin
theta1 = 0 # Initial angle of the first arm
theta2 = 0 # Initial angle of the second arm
# Lists to store (x, y) coordinates
xPoints = []
yPoints = []
for _ in range(maximum):
# Update angles
theta1 += 1 # First arm rotates at a constant speed
theta2 += constant # Second arm rotates at constant times the speed of the first arm
# Calculate new positions
x1_new = cos(radians(theta1))
y1_new = sin(radians(theta1))
x2 = cos(radians(theta2))
y2 = sin(radians(theta2))
# Calculate the endpoint of the second arm relative to the endpoint of the first arm
x2 += x1_new
y2 += y1_new
xPoints.append(x2)
yPoints.append(y2)
return (xPoints, yPoints)
goldenRatio = lambda maximum: irrationalProof(maximum, PHI)
mathPi = lambda maximum: irrationalProof(maximum, PI)