防止两个可拖动的圆相交时重叠 [英] Preventing two draggable circles from overlapping when they intersect

查看:121
本文介绍了防止两个可拖动的圆相交时重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都在寻找可以解决的简单方法。但是我是一个新程序员,有点麻烦。我的视图中有几个可拖动的图像视图圈子,我想防止图像视图之间出现任何重叠。我没有在寻找任何严重的碰撞解决方案(摩擦,矢量等),只是为了阻止图像视图在彼此接触后进一步前进。

Ive looked everywhere i could for what i am guessing has a simple solution. But i am a new programmer and am having a bit of trouble. I have a few draggable image view circles in my view and i want to prevent any overlapping between the image views. Im not looking for any serious collision solutions(friction, vectors, etc...), just something to stop the image views from going any further once they make contact with each other.

对解决方案的任何指导表示赞赏。谢谢。

Any guidance to the solution is appreciated. Thanks.

推荐答案

这应该只是位置和半径的简单比较...
尝试拖动时,计算两个圆的中心点之间的距离(使用新位置),如果该距离小于半径的总和,则它们会重叠。伪代码:

That should just be a simple comparison of location and radii... When a drag is attempted, compute the distance between any two circles' center points (using the new location), and if that's less than the sum of the radii, they overlap. Pseudocode:

onMoveAttempted()
{
distance = sqrt((((moving(x)-existingcircle(x))^ 2)+( (运动(y)-现有圆(y))^ 2))

onMoveAttempted() { distance = sqrt (((moving(x) - existingcircle(x))^2) + ((moving(y) - existingcircle(y))^2))

if(距离<(运动圆半径+现有圆半径)
那么
禁止移动,因为如果
},圈子将与
末端重叠

if (distance < (radius of moving circle + radius of existing circle) then prohibit the move, as the circles would overlap end if }

这篇关于防止两个可拖动的圆相交时重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆