Search code examples
c#winformsmathgraphicsopentk

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 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


Solution

  • 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)