iterse def squares_intersect (s1, 82): An axis-aligned square on the two-dimensional plane can be defined as a tuple (x, y, r) where (x, y) are the coordinates of its bottom left corner and r is the length of the side of the square. Given two squares as tuples (x1, y1, rl) and (x2, y2, r2), this function should determine whether these two squares intersect by having at least one point in common, even if that one point is the shared corner point of two squares placed kitty corner (The intersection of two squares can have zero area, if the intersection consists of parts of the one-dimensional edges.) This funetion should not contain any loops or list comprehensions of any kind, but should compute the result using only integer comparisons and conditional statements. This problem showcases an idea that comes up with some problems of this nature; it is actually far easier to determine that the two axis-aligned squares do not intersect, and negate that answer! Two squares do not intersect if one of them ends in the horizontal direction before the other one begins, or if the same thing happens in the vertical direction. (This technique generalizes from rectangles lying on the flat two-dimensional plane to not only three-dimensional cuboids, but to hyper-boxes of arbitrarily high dimensions.) 81 82 Expected result (2, 2, 3) (5, 5, 2) True (3, 6, 1) (8, 3, 5) False (8, 3, 3) (9, 6, 8) True (5, 4, 8) (3, 5, 5) True (10, 6, 2) (3, 10, 7) False

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter13: Structures
Section: Chapter Questions
Problem 4PP
icon
Related questions
Question
Interesting, Intersecting
def squares_intersect (s1, s2):
An axis-aligned square on the two-dimensional plane can be defined as a tuple (x, y, r) where
(x, y) are the coordinates of its bottom left corner and r is the length of the side of the square.
Given two squares as tuples (x1, yl, r1) and (x2, y2, r2), this function should determine
whether these two squares intersect by having at least one point in common, even if that one point
is the shared corner point of two squares placed kitty corner (The intersection of two squares can
have zero area, if the intersection consists of parts of the one-dimensional edges.) This function
should not contain any loops or list comprehensions of any kind, but should compute the result
using only integer comparisons and conditional statements.
This problem showcases an idea that comes up with some problems of this nature; it is actually far
easier to determine that the two axis-aligned squares do not intersect, and negate that answer! Two
squares do not intersect if one of them ends in the horizontal direction before the other one begins,
or if the same thing happens in the vertical direction. (This technique generalizes from rectangles
lying on the flat two-dimensional plane to not only three-dimensional cuboids, but to hyper-boxes
of arbitrarily high dimensions.)
81
82
Expected result
(2, 2, 3)
(5, 5, 2)
True
(3, 6, 1)
(8, 3, 5)
False
(8, 3, 3)
(9, 6, 8)
True
(5, 4, 8)
(3, 5, 5)
True
(10, 6, 2)
(3, 10, 7)
False
(3000, 6000, 1000)
(8000, 3000, 5000)
Falвe
(5*10**6, 4*10**6,
8*10**6)
(3*10**6, 5*10**6,
5*10**6)
True
Transcribed Image Text:Interesting, Intersecting def squares_intersect (s1, s2): An axis-aligned square on the two-dimensional plane can be defined as a tuple (x, y, r) where (x, y) are the coordinates of its bottom left corner and r is the length of the side of the square. Given two squares as tuples (x1, yl, r1) and (x2, y2, r2), this function should determine whether these two squares intersect by having at least one point in common, even if that one point is the shared corner point of two squares placed kitty corner (The intersection of two squares can have zero area, if the intersection consists of parts of the one-dimensional edges.) This function should not contain any loops or list comprehensions of any kind, but should compute the result using only integer comparisons and conditional statements. This problem showcases an idea that comes up with some problems of this nature; it is actually far easier to determine that the two axis-aligned squares do not intersect, and negate that answer! Two squares do not intersect if one of them ends in the horizontal direction before the other one begins, or if the same thing happens in the vertical direction. (This technique generalizes from rectangles lying on the flat two-dimensional plane to not only three-dimensional cuboids, but to hyper-boxes of arbitrarily high dimensions.) 81 82 Expected result (2, 2, 3) (5, 5, 2) True (3, 6, 1) (8, 3, 5) False (8, 3, 3) (9, 6, 8) True (5, 4, 8) (3, 5, 5) True (10, 6, 2) (3, 10, 7) False (3000, 6000, 1000) (8000, 3000, 5000) Falвe (5*10**6, 4*10**6, 8*10**6) (3*10**6, 5*10**6, 5*10**6) True
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr