2014-09-05 87 views
1

我有一个模拟手臂运动的代码。所以在每个单位时间之后,我确定手臂的位置并计算手臂位置和目标之间的简单距离。加上当手臂到达一个半径值为k的公差范围时,可以说手臂几乎达到了目标..我的问题是如何验证手臂是否到达公差圈
以下是代码非常简单半径公差圆

tolerance_radius = 0.3 
d = norm(cur_pos[0] - pos_tar[0]) #distance between arm and target array 

这是我曾尝试

if abs(d) <tolerance_radius : 
    #almost touched 
else: 
    #calculate new position 

是有,实际上可以创造整个公差圈,然后再确定是否手臂在圈内达到或没有这种特定的情况下,任何其他方式?

+0

我的坏!编辑。 – Hima 2014-09-05 12:41:05

回答

1

如果从手到目标的距离小于tolerance_radius,那么真,否则返回False:

if math.hypot(target.x - arm.x, target.y - arm.y) < tolerance_radius: 
    return True 
else 
    return False 
+0

有用的东西! – Hima 2014-09-05 12:51:12