简体   繁体   中英

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. 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? 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;

在此处输入图像描述

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? If the xy coordinate is the center, then you could use the distance formula:

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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