简体   繁体   English

如何找到圆的重叠

[英]how to find overlapping of circle

Hi there I made an application which has two balls.Red and Yellow.嗨,我做了一个应用程序,它有两个球。红色和黄色。 User has to drag RED BALL and drop it over the YELLOW BALL .it is in XY Plane.now i want to calculate what is the accuracy is the overlapping.用户必须拖动RED BALL并将其放在YELLOW BALL上。它在 XY 平面中。现在我想计算重叠的精度是多少。 I know that if the XY of target are equal to the XY of the Striker then it is 100 percent but how will you calculate it?我知道如果目标的 XY 等于 Striker 的 XY 那么它是 100% 但你将如何计算呢? as if you move the red ball further right value of X of striker gets bigger and percent will not be accurate?I have been using Percent Error formula but it is not accurate好像你把红球往右移动,前锋的 X 值变大,百分比不准确?我一直在使用百分比误差公式,但它不准确

   double percentErrorX =(CurrentX-targetX)*100/targetX;
            double percentErrorY = (CurrentY -targetY)*100/targetY;

在此处输入图像描述

I would think the most intuitive form of percentage calculation would come from computing the percentage of area of each circle that is overlapping.我认为最直观的百分比计算形式来自计算每个重叠圆圈的面积百分比。

What kind of granularity are you using?你使用什么样的粒度? And what does your xy coordinate represent, the center of each circle?你的 xy 坐标代表什么,每个圆的中心? If the xy coordinate is the center, then you could use the distance formula:如果 xy 坐标是中心,那么您可以使用距离公式:

d = sqrt[ (x1-x2)^2 + (y1-y2)^2 ]

Where the xy coords of the target are x1, y1 and the xy coords of the striker are x2, y2.其中目标的 xy 坐标为 x1, y1,前锋的 xy 坐标为 x2, y2。

With this d, you can computer a percentage like so:使用这个 d,您可以计算一个百分比,如下所示:

Percent = (d / radius)

there're many of types of collision.碰撞的种类很多。 and a good article for circle collision: http://compsci.ca/v3/viewtopic.php?t=14897还有一篇关于圆碰撞的好文章: http://compsci.ca/v3/viewtopic.php?t=14897

You need some math to calculate the exact result but here is an eat way that will give you good approximation.你需要一些数学来计算确切的结果,但这里有一种吃法,可以给你很好的近似值。 Calculate the distance between the balls by sqrt((x1-x2)^2+(y1-y2)^2) Your result is approximately (distance/radius*2)^1.8 try thus formulae and see if the precision is good enough通过 sqrt((x1-x2)^2+(y1-y2)^2) 计算球之间的距离 你的结果大约是 (distance/radius*2)^1.8 试试这样的公式,看看精度是否足够好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM