A rectangle is a geometric shape: any quadrilateral with four right angles
Questions tagged [rectangles]
1373 questions
400
votes
21 answers
Determine if two rectangles overlap each other?
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…

Rob Burke
- 5,365
- 4
- 31
- 30
101
votes
7 answers
Efficient (and well explained) implementation of a Quadtree for 2D collision detection
I've been working on adding a Quadtree to a program that I'm writing, and I can't help but notice that there are few well explained/performing tutorials for the implementation that I'm looking for.
Specifically, a list of the methods and pseudocode…

Zimri Leisher
- 1,236
- 3
- 10
- 14
83
votes
2 answers
Algorithm for finding the fewest rectangles to cover a set of rectangles without overlapping
I have a set of rectangles and I would like to "reduce" the set so I have the fewest number of rectangles to describe the same area as the original set. If possible, I would like it to also be fast, but I am more concerned with getting the number of…

Mike Dour
- 3,616
- 2
- 22
- 24
40
votes
5 answers
Get the points of intersection from 2 rectangles
Let say that we have two rectangles, defined with their bottom-left and top-right corners. For example: rect1 (x1, y1)(x2, y2) and rect2 (x3, y3)(x4, y4).
I'm trying to find the coordinates(bottom-left and top-right) of the intersected…

NoSense
- 949
- 2
- 11
- 21
35
votes
2 answers
How to draw a rounded rectangle in c#
I am using this code to make a rounded rectangle. But it only draws upper left and right corners of rectanlge , more it doest not complete the rectangle at lower part. How to make it complete and filled . What changes should I make ?
public static…

phpnet
- 903
- 1
- 8
- 23
33
votes
2 answers
Qt drawing a filled rounded rectangle with border
I want to draw a rectangle with rounded corners (border radius same for all 4 corners) with a specific color filling the entire rectangle, and a separate border color (say border is 1 px wide).
From my observation, Qt provides three methods -…

SexyBeast
- 7,913
- 28
- 108
- 196
31
votes
2 answers
How to add a text into a Rectangle?
I have a code that draws hundreds of small rectangles on top of an image :
The rectangles are instances of
matplotlib.patches.Rectangle
I'd like to put a text (actually a number) into these rectangles, I don't see a way to do that.…

tm8cc
- 1,111
- 2
- 12
- 26
27
votes
10 answers
How to calculate distance between two rectangles? (Context: a game in Lua.)
Given two rectangles with x, y, width, height in pixels and a rotation value in degrees -- how do I calculate the closest distance of their outlines toward each other?
Background: In a game written in Lua I'm randomly generating maps, but want to…

Philipp Lenssen
- 8,818
- 13
- 56
- 77
26
votes
4 answers
How to check whether a NSPoint lays inside a NSRect
I've created a mutable array containing NSRect values. I want to check whether the NSPoint I created is within this rectangle. What is the best way to do this in cocoa.
Luuk
26
votes
6 answers
Pygame Drawing a Rectangle
I'm making a game that requires knowing how to draw a rectangle in Python (3.2).
I have checked lot of sources but none show exactly how to do it.
user2399874
24
votes
12 answers
Rectangles Covering
I have N rectangles with sides parallel to the x- and y-axes. There is another rectangle, model. I need to create an algorithm that can tell whether the model is completely covered by the N rectangles.
I have some ideas. I think that first, I…

den bardadym
- 2,747
- 3
- 25
- 27
23
votes
5 answers
Merging multiple adjacent rectangles into one polygon
Background: I am working on a site for small shopping center, which has multiple rectangular "units" to rent. When a "shop" comes, it can rent one or multiple "units", and I'd like to generate a map consisting of shops (sans unrented…

Adam Kiss
- 11,811
- 9
- 48
- 81
22
votes
4 answers
Finding an axis-aligned rectangle inside a polygon
I am looking for a good algorithm to find an axis-aligned rectangle inside a (not necessarily convex) polygon. A maximal rectangle would be nice, but is not necessary - any algorithm that can find a "fairly good" rectangle would be fine.
The polygon…

Joel in Gö
- 7,460
- 9
- 47
- 77
22
votes
5 answers
How do I see if two rectangles intersect in JavaScript or pseudocode?
I have two rectangles which I must return in a function whether they intersect or not.
They are represented by [ x0, y0, x1, y1 ] pairs that represent the top-left and bottom-right corner of the rectangles. Alternatively, your solution could be […

Discipol
- 3,137
- 4
- 22
- 41
20
votes
3 answers
OpenCV groupRectangles - getting grouped and ungrouped rectangles
I'm using OpenCV and want to group together rectangles that have significant overlap. I've tried using groupRectangles for this, which takes a group threshold argument. With a threshold of 0 it doesn't do any grouping at all, and with a threshold of…

Ben Dowling
- 17,187
- 8
- 87
- 103