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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:37:30+00:00 2026-05-27T07:37:30+00:00

This is a homework assignment, so I’m mostly asking for a nudge in the

  • 0

This is a homework assignment, so I’m mostly asking for a nudge in the right direction. I’ve figured out the majority of the problem. We have a Rectangle class, whose rectangles are defined by the x and y coordinates in a Point class. The one part I’m stuck on is figuring out if the two rectangles intersect. I’ve done some research, and came upon this:

http://silentmatt.com/rectangle-intersection/

That helps me with how it would need to be done. But I can’t seem to implement it in the way that our teacher had it setup in the problem overview:

//This method returns true if this rectangle intersects with another rectangle (which is provided as a parameter)
bool intersects(Rectangle);

The intersects function only takes one parameter, that is of the Rectangle class. The call to it in main is something like this:

rec1.intersects(rec2);

I can’t seem to figure out how to implement the actual function, though. I’ve already defined the points for both rec1 and rec2 with setters, but I can’t seem to figure out how to access those points with the function that only accepts the one parameter. Because, in the example above, I can access the x and y points for rec2, but I can’t with rec1.

Any tips on how to proceed?

EDIT: I think part of my problem is just how this was implemented. Here’s what we have in the Rectangle class:

private:
Point lowerLeftCorner;
Point upperRightCorner;

And then he had us setup get and set functions in the Point class to set the points for lowerLeftCorner and upperRightCorner.

The problem is when I’m in the intersect function, I can ONLY (unless I’m missing something) use the get functions for the parameter (rectangle2) and not for the first rectangle (rectangle1).

If I was able to pass both rectangles as parameters, I could use the given examples to solve this. It’s being able to find the values of x and y for the first rectangle that’s giving me trouble.

EDIT: Robert’s info helped me figure out how to do it using “this”. Here’s what I ended up with which seems to work well. It’s probably not the best, I am still pretty new to programming.

bool Rectangle::intersects(Rectangle rec2) {
    return ( getupperX() > rec2.getlowerX() &&
    getlowerX() < rec2.getupperX() &&
    getupperY() > rec2.getlowerY() &&
    getlowerY() < rec2.getupperY());
    }
}

Seems to have worked for all the values I’ve tested!

  • 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-27T07:37:31+00:00Added an answer on May 27, 2026 at 7:37 am

    In C++, if you’re inside a member function of class, you have access to the member variables of that class implicitly.

    So if you had

    struct Rectangle 
    {
      Point UpperLeft;
      Point LowerRight;
      bool intersects(Rectangle);
    }
    

    Then within the intersects() function, because it is a member of the class, you can access member variables of that class, like this:

    Rectangle::intersects(Rectangle rhs)
    {
      // So the second UpperLeft here is a member of "this" instance of the class
      if(rhs.UpperLeft < UpperLeft)
        return true;
    }
    

    That function won’t actually detect intersection, but that’s how you would access all the points.

    So if you had:

    Rectangle rect_a;
    Rectangle rect_b;
    rect_a.intersects(rect_b);
    

    Then you would be calling rect_a‘s intersects() function, so it would be “this” in the example above, where rect_b would be rhs

    EDIT:
    Alternatively, in your example above, you could write something like

    Rectangle::intersects(Rectangle rhs)
    {
      if(rhs.GetLowerLeft() < GetLowerLeft())
        return true;
    }
    

    And the second GetLowerLeft() would be called on “this”

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

Sidebar

Related Questions

Continuing on this problem , but I'll reiterate: For a homework assignment I have
This was a homework assignment problem which I know I have incorrectly answered. I
This is part of a homework assignment. I've got several questions asking find the
(this is indirectly a part of a much larger homework assignment) I have something
Note: This is a homework assignment. I have two classes, one inherits from the
This is part of a homework assignment. What we have to do is write
I'm still not very good with data structures, but I have this homework assignment
This is a homework assignment. I just need a nudge. I'm trying to create
Disclaimer: This is for a homework assignment, but the question is not regarding the
I'm doing a basic homework assignment which looks like this: While input <> -1

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.