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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:57:08+00:00 2026-05-10T20:57:08+00:00

I am trying to write a C++ program that takes the following inputs from

  • 0

I am trying to write a C++ program that takes the following inputs from the user to construct rectangles (between 2 and 5): height, width, x-pos, y-pos. All of these rectangles will exist parallel to the x and the y axis, that is all of their edges will have slopes of 0 or infinity.

I’ve tried to implement what is mentioned in this question but I am not having very much luck.

My current implementation does the following:

// Gets all the vertices for Rectangle 1 and stores them in an array -> arrRect1 // point 1 x: arrRect1[0], point 1 y: arrRect1[1] and so on... // Gets all the vertices for Rectangle 2 and stores them in an array -> arrRect2  // rotated edge of point a, rect 1 int rot_x, rot_y; rot_x = -arrRect1[3]; rot_y = arrRect1[2]; // point on rotated edge int pnt_x, pnt_y; pnt_x = arrRect1[2];  pnt_y = arrRect1[3]; // test point, a from rect 2 int tst_x, tst_y; tst_x = arrRect2[0]; tst_y = arrRect2[1];  int value; value = (rot_x * (tst_x - pnt_x)) + (rot_y * (tst_y - pnt_y)); cout << 'Value: ' << value;   

However I’m not quite sure if (a) I’ve implemented the algorithm I linked to correctly, or if I did exactly how to interpret this?

Any suggestions?

  • 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. 2026-05-10T20:57:09+00:00Added an answer on May 10, 2026 at 8:57 pm
    if (RectA.Left < RectB.Right && RectA.Right > RectB.Left &&      RectA.Top > RectB.Bottom && RectA.Bottom < RectB.Top )  

    or, using Cartesian coordinates

    (With X1 being left coord, X2 being right coord, increasing from left to right and Y1 being Top coord, and Y2 being Bottom coord, increasing from bottom to top — if this is not how your coordinate system [e.g. most computers have the Y direction reversed], swap the comparisons below) …

    if (RectA.X1 < RectB.X2 && RectA.X2 > RectB.X1 &&     RectA.Y1 > RectB.Y2 && RectA.Y2 < RectB.Y1)  

    Say you have Rect A, and Rect B. Proof is by contradiction. Any one of four conditions guarantees that no overlap can exist:

    • Cond1. If A’s left edge is to the right of the B’s right edge, – then A is Totally to right Of B
    • Cond2. If A’s right edge is to the left of the B’s left edge, – then A is Totally to left Of B
    • Cond3. If A’s top edge is below B’s bottom edge, – then A is Totally below B
    • Cond4. If A’s bottom edge is above B’s top edge, – then A is Totally above B

    So condition for Non-Overlap is

    NON-Overlap => Cond1 Or Cond2 Or Cond3 Or Cond4

    Therefore, a sufficient condition for Overlap is the opposite.

    Overlap => NOT (Cond1 Or Cond2 Or Cond3 Or Cond4)

    De Morgan’s law says
    Not (A or B or C or D) is the same as Not A And Not B And Not C And Not D
    so using De Morgan, we have

    Not Cond1 And Not Cond2 And Not Cond3 And Not Cond4

    This is equivalent to:

    • A’s Left Edge to left of B’s right edge, [RectA.Left < RectB.Right], and
    • A’s right edge to right of B’s left edge, [RectA.Right > RectB.Left], and
    • A’s top above B’s bottom, [RectA.Top > RectB.Bottom], and
    • A’s bottom below B’s Top [RectA.Bottom < RectB.Top]

    Note 1: It is fairly obvious this same principle can be extended to any number of dimensions.
    Note 2: It should also be fairly obvious to count overlaps of just one pixel, change the < and/or the > on that boundary to a <= or a >=.
    Note 3: This answer, when utilizing Cartesian coordinates (X, Y) is based on standard algebraic Cartesian coordinates (x increases left to right, and Y increases bottom to top). Obviously, where a computer system might mechanize screen coordinates differently, (e.g., increasing Y from top to bottom, or X From right to left), the syntax will need to be adjusted accordingly/

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

Sidebar

Ask A Question

Stats

  • Questions 190k
  • Answers 190k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sounds like it's drupal that is handling the search. Google… May 12, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer Try this: DataContractSerializer world_serializer = new DataContractSerializer(typeof(World), new List<Type> {… May 12, 2026 at 5:59 pm
  • Editorial Team
    Editorial Team added an answer It used to be that to disable an element, you… May 12, 2026 at 5:59 pm

Related Questions

I am trying to write a c++ program that responds to keyboard input. I
I am attempting to write a time management tool with wxPython that is ideally
I am trying to start unit testing. I am looking at a few C++
Whats the best way to go about modifying a C++ program to be used

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.