Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:57:22+00:00 2026-06-10T20:57:22+00:00

Below is a function that detects if two circles intersect. I want to change

  • 0

Below is a function that detects if two circles intersect. I want to change it to only detect if the periferi of the circles intersect. Hence, if circle A is completely inside circle B, there is no collision!

How?

private bool IsCircleCollision(
    int x1, int y1, int radius1,
    int x2, int y2, int radius2)
{
    int dx = x2 - x1;
    int dy = y2 - y1;

    int distance = (dx * dx) + (dy * dy);

    int radii = radius1 + radius2;
    if (distance < radii * radii)
    {
        return true;
    }
    else
    {
        return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:57:24+00:00Added an answer on June 10, 2026 at 8:57 pm

    You work this out by calculating the distance between the two centres, D say. There is an intersection if

    abs(R1-R2) < D < R1+R2
    

    where R1 and R2 are the radii of the two circles.

    The first test, abs(R1-R2) < D handles the case when one circle’s centre is inside the other’s. And the second test, D < R1+R2, handles the case when neither circle contains the other’s centre.

    So, adapting your code we have:

    private bool IsCircleCollision(
        int x1, int y1, int radius1,
        int x2, int y2, int radius2)
    {
        int dx = x2 - x1;
        int dy = y2 - y1;
    
        double D = Math.Sqrt(dx*dx + dy*dy);
        return Math.Abs(radius1-radius2)<D && D<radius1+radius2;
    }
    

    If performance is important here, you can do without the call to Math.Sqrt like this:

    private bool IsCircleCollision(
        int x1, int y1, int radius1,
        int x2, int y2, int radius2)
    {
        int dx = x2 - x1;
        int dy = y2 - y1;
    
        int Dsqr = dx*dx + dy*dy;
        int rdiff = Math.Abs(radius1-radius2);
        int rsum = radius1+radius2
        return rdiff*rdiff<Dsqr && D<rsum*rsum;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that can return the difference between the below two dates
Below is my function that will take a timestamp and tell you the time
I have an example function below that reads in a date as a string
Below I have a function that animates a div ( container ) either to
I Send Iqueryable to a function that is below void Method<T>(ref IQueryable<T> qu) {
How is this possible that the str_replace() function below returns biWeekly and not Every
I'm appending to a list then throwing that list into a function below: List<ItemBean>
somebody mentioned that the function (in this case a method) below is no good
is there a function in PHP that could parse the html data below to
I had a query as below in my function. In that I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.