use numpy array

This commit is contained in:
Zhengyu Peng
2021-12-09 08:53:12 -05:00
parent 1f8b6a7826
commit 836d80e9b6
2 changed files with 42 additions and 36 deletions

View File

@ -9,25 +9,24 @@ def semicircle_generator(radius, steps, reverse=False):
step_angle = np.pi / halfsteps
result = []
result = np.zeros((steps, 3))
halfsteps_array = np.arange(halfsteps)
# first half, move backward (only y change)
for i in range(halfsteps):
result.append((0, radius - i*radius*2/(halfsteps), 0))
result[:halfsteps, 1] = radius - halfsteps_array*radius*2/(halfsteps)
# second half, move forward in semicircle shape (y, z change)
for i in range(halfsteps):
angle = np.pi - step_angle*i
y = radius * math.cos(angle)
z = radius * math.sin(angle)
result.append((0, y, z))
angle = np.pi - step_angle*halfsteps_array
y = radius * np.cos(angle)
z = radius * np.sin(angle)
result[halfsteps:, 1] = y
result[halfsteps:, 2] = z
result = deque(result)
result.rotate(int(steps/4))
result = np.roll(result, int(steps/4), axis=0)
if reverse:
result = deque(reversed(result))
result.rotate(1)
result = np.flip(result, axis=0)
result = np.roll(result, 1, axis=0)
return result