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 6649085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:43:56+00:00 2026-05-26T00:43:56+00:00

What I’m doing is testing to see what the level of intersection between a

  • 0

What I’m doing is testing to see what the level of intersection between a circle and rectangle. I would like to find whether the rectangle is completely inside the circle, partially intersecting it, or if there is no intersection at all.

I’ve attached the code that I’ve come up with today, it simply checks the distances from the center of the circle to the corners of the rectangle to determine the level of intersection.

What I’m wondering is there a more efficient way of doing this?

EDIT:
Here is my updated, working code. fullIntersect is my own, I found the partialIntersect snippet on Circle-Rectangle collision detection (intersection). I’m going to leave this open, as I’m still curious as to whether there is a better way of doing this.

    public boolean fullIntersect(float circleX, float circleY, float radius)
    {
        float radsq = radius * radius;
        double xsq = Math.pow(circleX - xPosition, 2);
        double xpwsq = Math.pow(circleX - (xPosition + width), 2);
        double ysq = Math.pow(circleY - yPosition, 2);
        double yphsq = Math.pow(circleY - (yPosition + height), 2);

        if(xsq + ysq > radsq || xsq + yphsq > radsq || xpwsq + yphsq > radsq || xpwsq + ysq > radsq)
            return false;

        return true;

        /* this is what the one if statement does
        double disBotLeft = xsq + ysq;
        double disTopLeft = xsq + yphsq;
        double disTopRight = xpwsq + yphsq;
        double disBotRight = xpwsq + ysq;

        if(disBotRight > radsq) return false;
        if(disBotLeft > radsq) return false;
        if(disTopLeft > radsq) return false;
        if(disTopRight > radsq) return false;

        return true;
        */
    }

    public int intersects(float circleX, float circleY, float radius)
    {
        if(!enabled) return 0;
        double wo2 = width / 2.0d;
        double ho2 = height / 2.0d;

        double circleDistanceX = Math.abs(circleX - xPosition - wo2);
        double circleDistanceY = Math.abs(circleY - yPosition - ho2);

        if (circleDistanceX > (wo2 + radius)) { return 0; }
        if (circleDistanceY > (ho2 + radius)) { return 0; }

        if(fullIntersect(circleX, circleY, radius)) { return 2; }

        if (circleDistanceX <= (wo2)) { return 1; } 
        if (circleDistanceY <= (ho2)) { return 1; }

        double cornerDistance_sq = Math.pow(circleDistanceX - wo2,2) +
                             Math.pow(circleDistanceY - ho2,2);

        return cornerDistance_sq <= (radius*radius) ? 1 : 0;
    }
  • 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-05-26T00:43:57+00:00Added an answer on May 26, 2026 at 12:43 am

    I think your code does not consider these intersections:

    enter image description here

    I’ll delete this answer as soon as you enhance your code/question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

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.