Preventing two draggable circles from overlapping when they intersect

℡╲_俬逩灬. 提交于 2019-12-12 00:58:57

问题


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.


回答1:


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) + ((moving(y) - existingcircle(y))^2))

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



来源:https://stackoverflow.com/questions/16404454/preventing-two-draggable-circles-from-overlapping-when-they-intersect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!