-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeomForm.py
75 lines (65 loc) · 2.07 KB
/
geomForm.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
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
import numpy as np
def randomFace(n, bool1, bool2):
res1 = np.random.uniform(0,1, n)
res1 = bool1 + np.logical_not(bool1) * res1
res1 = np.logical_not(bool2) * res1
return res1
def cube(n):
u = np.random.uniform(0,1,n)
bool1 = u <= 1/6
bool2 = (u <= 2/6) & (u > 1/6)
bool3 = (u <= 3/6) & (u > 2/6)
bool4 = (u <= 4/6) & (u > 3/6)
bool5 = (u <= 5/6) & (u > 4/6)
bool6 = (u <= 6/6) & (u > 5/6)
first = randomFace(n, bool1, bool2)
second = randomFace(n, bool3, bool4)
third = randomFace(n, bool5, bool6)
res = [first, second, third]
res = np.transpose(res)
return res
def circle(n):
first = np.zeros(n)
theta = np.random.uniform(0, 2*np.pi, n)
second = np.cos(theta)
third = np.sin(theta)
res = [first, second, third]
res = np.transpose(res)
return res
def sphere(n):
theta = np.random.uniform(0, 2*np.pi, n)
phi = np.random.uniform(0, 2*np.pi, n)
first = np.sin(theta) * np.cos(phi)
second = np.sin(theta) * np.sin(phi)
third = np.cos(theta)
res = [first, second, third]
res = np.transpose(res)
return res
def torrus(n):
phi = np.random.uniform(0, 2*np.pi, n)
theta = np.random.uniform(0, 2*np.pi, n)
z = 0.25 * np.sin(theta)
lho = 0.75 + 0.25 * np.cos(theta)
x = lho *np.cos(phi)
y = lho * np.sin(phi)
res = [x,y,z]
res = np.transpose(res)
return res
def threeCluster(n):
m=int(np.floor(n/3))
centers = np.random.uniform(0,1,(3,3))
cluster0 = centers[0,:] + 0.1*sphere(m)
cluster1 = centers[1,:] + 0.1*sphere(m)
cluster2 = centers[2,:] + 0.1*sphere(m)
res = np.append(cluster0, cluster1, axis=0)
res = np.append(res, cluster2, axis=0)
return res
def threeClusterInThreeCluster(n):
m=int(np.floor(n/3))
centers = np.random.uniform(0,1,(3,3))
cluster0 = centers[0,:] + 0.1*threeCluster(m)
cluster1 = centers[1,:] + 0.1*threeCluster(m)
cluster2 = centers[2,:] + 0.1*threeCluster(m)
res = np.append(cluster0, cluster1, axis=0)
res = np.append(res, cluster2, axis=0)
return res