沿触摸路径移动对象

时间:2019-07-03 09:13:31

标签: android path geometry

我有一个笔划圆路径和一个小填充圆路径,并且我想沿笔划圆路径沿触摸方向移动该小圆,该小圆不应位于笔划圆之外。我怎样才能做到这一点 ?请帮助我

1 个答案:

答案 0 :(得分:0)

您的触摸可能不在您的圈子路径之外。要提供对象在圆上的位置,可以进行下一个:

    find position of touch against circle center
dx = touch.x - center.x
dy = touch.y - center.y
    find distance from the center
dist = sqrt(dx*dx +dy*dy)
     make new position at the same disraction form center but at circle radius distance
newx = center.x + radius * dx / dist
newy = center.y + radius * dy / dist
相关问题