【发布时间】:2019-11-13 22:37:55
【问题描述】:
我有一个描边圆路径和一个小填充圆路径,我想通过触摸沿着描边圆路径移动小圆,小圆不应该在描边圆之外。我怎样才能做到这一点 ?请帮帮我
【问题讨论】:
我有一个描边圆路径和一个小填充圆路径,我想通过触摸沿着描边圆路径移动小圆,小圆不应该在描边圆之外。我怎样才能做到这一点 ?请帮帮我
【问题讨论】:
您的触摸可能略微超出您的圈子路径。要提供圆上的对象位置,您可以进行以下操作:
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
【讨论】: