use numpy array
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user