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

  • Home
  • SEARCH
  • 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 3232176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:07:50+00:00 2026-05-17T17:07:50+00:00

given an edge enum such as this: none, top, left, bottom, right, Given 2

  • 0

given an edge enum such as this:

none, top, left, bottom, right,

Given 2 rectangles, how could I find which edge of rectangle A that rectangle B is intersecting? I do not need to know which edge of B hit an edge of A, I just need to know which edge of A that B hit.

I found this algorithm but it does not return the specific edge:

bool edgeIntersection( vector2f a, vector2f b, DOUBLEPOINT c, DOUBLEPOINT d )
{
    //one edge is a-b, the other is c-d
    vector2f bminusa;
    vector2f cminusa;
    vector2f cminusd;

    bminusa.x = b.x - a.x;
    bminusa.y = b.y - a.y;

    cminusa.x = c.point[0] - a.x;
    cminusa.y = c.point[1] - a.y;

    cminusd.x = c.point[0] - d.point[0];
    cminusd.y = c.point[1] - d.point[1];

    double det=determinant(bminusa,cminusd);
    double t=determinant(cminusa,cminusd)/det;
    double u=determinant(bminusa,cminusa)/det;
    if ((t<0)||(u<0)||(t>1)||(u>1))return false;
    return true;
}

My above algorithm checks each edge one by one, given
TopLeftA TopLeftB BottomRightA BottomRightB, how could I make a function I only need to call once?

Thanks

  • 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-17T17:07:51+00:00Added an answer on May 17, 2026 at 5:07 pm

    Assuming you’ve used edgeIntersection to determine that an intersection has occurred, then:

    if (b.x < a.x) return left;
    if (b.y < a.y) return top;
    if (b.x+b.width > a.x+a.width) return right;
    return bottom;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a bit bleeding edge, but here's the question anyway: Given
Given a (source) patch file, what's the easiest way to apply this patch on
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this
Given a latitude and longitude, what is the easiest way to find the name
Given n squares with edge length l , how can I determine the minimum
Given a directed, connected graph with only positive edge weights, are there faster algorithms
Given a 2d picture of a rectangle distorted by perspective: I know that the
This is my code: typedef std::hash_multimap<Vertice<VerticeType, WeightType>*, Edge<VerticeType, WeightType>*> ght; std::pair<ght::iterator, ght::iterator> getEdgesFromVertice(Vertice<VerticeType, WeightType>*);
I am given a string of characters, in which every consequent pair of characters
Suppose I am given a weighted, connected graph. I'd like to find a list

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.