如何找到圆的重叠部分

发布于 2024-11-15 10:59:36 字数 414 浏览 3 评论 0原文

您好,我制作了一个有两个球的应用程序。红色和黄色。 用户必须拖动红球并将其放在黄球上。它位于 XY 平面中。现在我想计算重叠的精度是多少。我知道如果目标的 XY 等于前锋的 XY,那么它就是 100%,但是你将如何计算它呢?就好像你将红球向右移动,前锋的 X 值变大,百分比将不准确?我一直在使用百分比误差公式,但它不准确

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

在此处输入图像描述

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 X-Y Plane.now i want to calculate what is the accuracy is the overlapping. I know that if the X-Y of target are equal to the X-Y of the Striker then it is 100 percent but how will you calculate it? 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

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

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半﹌身腐败 2024-11-22 10:59:36

我认为最直观的百分比计算形式是计算每个重叠圆的面积百分比。

您使用什么样的粒度?你的 xy 坐标代表什么,每个圆的中心?如果 xy 坐标为中心,则可以使用距离公式:

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

其中目标的 xy 坐标为 x1、y1,前锋的 xy 坐标为 x2、y2。

使用这个 d,您可以像这样计算百分比:

Percent = (d / radius)

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 x-y coordinate represent, the center of each circle? If the x-y coordinate is the center, then you could use the distance formula:

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

Where the x-y coords of the target are x1, y1 and the x-y coords of the striker are x2, y2.

With this d, you can computer a percentage like so:

Percent = (d / radius)
红玫瑰 2024-11-22 10:59:36

碰撞有很多种类型。还有一篇关于圆形碰撞的好文章:
http://compsci.ca/v3/viewtopic.php?t=14897

there're many of types of collision. and a good article for circle collision :
http://compsci.ca/v3/viewtopic.php?t=14897

⊕婉儿 2024-11-22 10:59:36

您需要一些数学来计算准确的结果,但这里有一种饮食方法可以为您提供良好的近似值。
通过 sqrt((x1-x2)^2+(y1-y2)^2) 计算球之间的距离
您的结果约为(距离/半径*2)^1.8
尝试这样的公式,看看精度是否足够好

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文