-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccel.py
More file actions
138 lines (109 loc) · 3.32 KB
/
Copy pathaccel.py
File metadata and controls
138 lines (109 loc) · 3.32 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
131
132
133
134
135
136
137
138
import numpy as np
from numba import vectorize
import math
def translate(origins, offset):
ofx, ofy, ofz = offset
x,y,z = [],[],[]
for i in origins:
x.append(i[0])
y.append(i[1])
z.append(i[2])
x = np.array(x, dtype=np.float32)
y = np.array(y, dtype=np.float32)
z = np.array(z, dtype=np.float32)
ofx = np.full(len(x), ofx, dtype=np.float32)
ofy = np.full(len(y), ofy, dtype=np.float32)
ofz = np.full(len(z), ofz, dtype=np.float32)
if len(x) < 1000: f = trans_c
else: f = trans_c
nx = f(x, ofx)
ny = f(y, ofy)
nz = f(z, ofz)
return list(zip(nx,ny,nz))
@vectorize(['float32(float32, float32)'], target='cuda')
def trans_c(start, off):
return start + off
def trans(start, off):
return start + off
@vectorize(['float32(float32, float32, float32)'], target='cuda')
def rotx_c(px, py, angle):
qx = math.cos(angle) * (px) - math.sin(angle) * (py)
return qx
def rotx(px, py, angle):
qx = math.cos(angle) * (px) - math.sin(angle) * (py)
return qx
@vectorize(['float32(float32, float32, float32)'], target='cuda')
def roty_c(px, py, angle):
qy = math.sin(angle) * (px) + math.cos(angle) * (py)
return qy
def roty(px, py, angle):
qy = math.sin(angle) * (px) + math.cos(angle) * (py)
return qy
def rot(px, py, angle):
return rotx(px, py, angle), roty(px, py, angle)
def rot_c(px, py, angle):
return rotx_c(px, py, angle), roty_c(px, py, angle)
def rotate(starts, origin, rotation):
rox, roy, roz = rotation
ox, oy, oz = origin
x, y, z = [], [], []
for i in starts:
x.append(i[0])
y.append(i[1])
z.append(i[2])
x = np.array(x, dtype=np.float32)
y = np.array(y, dtype=np.float32)
z = np.array(z, dtype=np.float32)
ofx = np.full(len(x), -ox, dtype=np.float32)
ofy = np.full(len(y), -oy, dtype=np.float32)
ofz = np.full(len(z), -oz, dtype=np.float32)
if len(x) < 1000:
f = rot
t = trans
else:
f = rot_c
t = trans_c
nx = t(x, ofx)
ny = t(y, ofy)
nz = t(z, ofz)
nx, ny = f(nx, ny, roz)
nx, nz = f(nx, nz, roy)
ny, nz = f(ny, nz, rox)
ofx = np.full(len(x), ox, dtype=np.float32)
ofy = np.full(len(y), oy, dtype=np.float32)
ofz = np.full(len(z), oz, dtype=np.float32)
nx = t(nx, ofx)
ny = t(ny, ofy)
nz = t(nz, ofz)
return list(zip(nx, ny, nz))
@vectorize(['float32(float32, float32, float32)'], target='cuda')
def sca_c(origin, start, factor):
dist = start - origin
dist = dist * factor
pos = dist + origin
return pos
def sca(origin, start, factor):
dist = start - origin
dist = dist * factor
pos = dist + origin
return pos
def scale(starts, origin, factor):
ox, oy, oz = origin
x, y, z = [], [], []
for i in starts:
x.append(i[0])
y.append(i[1])
z.append(i[2])
x = np.array(x, dtype=np.float32)
y = np.array(y, dtype=np.float32)
z = np.array(z, dtype=np.float32)
ofx = np.full(len(x), ox, dtype=np.float32)
ofy = np.full(len(y), oy, dtype=np.float32)
ofz = np.full(len(z), oz, dtype=np.float32)
factor = np.full(len(x), factor, dtype=np.float32)
if len(x) < 1000: f = sca
else: f = sca_c
x = f(ofx, x, factor)
y = f(ofy, y, factor)
z = f(ofz, z, factor)
return list(zip(x, y, z))