def reshape(self, vertices):
"""Make snake smoother."""
arc_length = 0
# calculate the total arc-length
for i in range(1, self.length):
arc_length += norm(vertices[i] - vertices[i - 1])
# average length for each segment
seg_length = arc_length / (self.length - 1)
if self._bc == 'PBC':
arc_length += norm(vertices[0] - vertices[-1])
seg_length = arc_length / self.length
for i in range(1, self.length - 1 if self._bc == 'OBC' else self.length):
# normalized tangent direction at node i-1
tan_direction = vertices[i] - vertices[i - 1]
tan_direction /= norm(tan_direction)
# move node i
vertices[i] = vertices[i - 1] + tan_direction * seg_length
return vertices
评论列表
文章目录