def getMagnitudeAndDirection(*args):
'''
Gets the magnitude and direction of the vector corresponding to positions
params:
args: Can be a list of two positions or the two positions themselves (variable-length argument)
'''
if len(args) == 1:
pos_list = args[0]
pos_i = pos_list[0]
pos_j = pos_list[1]
vector = np.array(pos_i) - np.array(pos_j)
magnitude = np.linalg.norm(vector)
if abs(magnitude) > 1e-4:
direction = vector / magnitude
else:
direction = vector
return [magnitude] + direction.tolist()
elif len(args) == 2:
pos_i = args[0]
pos_j = args[1]
ret = torch.zeros(3)
vector = pos_i - pos_j
magnitude = torch.norm(vector)
if abs(magnitude) > 1e-4:
direction = vector / magnitude
else:
direction = vector
ret[0] = magnitude
ret[1:3] = direction
return ret
else:
raise NotImplementedError('getMagnitudeAndDirection: Function signature incorrect')
评论列表
文章目录