-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphericalSimulatorFast.py
More file actions
130 lines (63 loc) · 2.12 KB
/
SphericalSimulatorFast.py
File metadata and controls
130 lines (63 loc) · 2.12 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 14 14:19:04 2019
@author: ckuli
"""
#(r,theta,phi)
r = 1
n = 0
numPointsToSim = 5000000
import math
import random
def isclose(a,b,sig_fig=5):
return (a==b or int(a*10**sig_fig) == int(b*10**sig_fig))
def dist(a,b):
theta1 = a[1]
phi1 = a[2]
x1 = math.cos(theta1)*math.sin(phi1)
y1 = math.sin(theta1)*math.sin(phi1)
z1 = math.cos(phi1)
theta2 = b[1]
phi2 = b[2]
x2 = math.cos(theta2)*math.sin(phi2)
y2 = math.sin(theta2)*math.sin(phi2)
z2 = math.cos(phi2)
return math.sqrt(((x1 - x2)**2) + ((y1 - y2)**2) + ((z1 - z2)**2))
def genOrdering(a,points):
ordering = []
dists = []
tdists = []
for p in points:
dists.append(dist(a,p))
tdists.append(dist(a,p))
while len(tdists) > 0:
minD = min(tdists)
ordering.append(dists.index(minD))
tdists.remove(minD)
return ordering
maxes = [0] * 26
while True:
#Generate random established points on the sphere.
num = n
points = []
for i in range(num):
theta = random.uniform(0.0,3.1415)
phi = random.uniform(0.0,3.1415*2)
points.append([r,theta,phi])
orderings = []
#Test a lot of random points.
for i in range(numPointsToSim):
theta0 = random.uniform(0.0,math.pi)
phi0 = random.uniform(0.0,math.pi*2)
point = [1,theta0,phi0]
order = genOrdering(point,points)
if order not in orderings:
orderings.append(order)
numOrds = len(orderings)
if maxes[n] < numOrds:
maxes[n] = numOrds
print("New max for n = " + str(n) +": " + str(numOrds))
print(maxes)
n = (n + 1) % 26
if n == 0:
n = n + 3 % 26