Questions tagged [rectangles]

A rectangle is a geometric shape: any quadrilateral with four right angles

1277 questions
351
votes
23 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
  • 4,845
  • 4
  • 26
  • 29
80
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,466
  • 2
  • 20
  • 24
73
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
  • 936
  • 1
  • 8
  • 12
33
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
  • 881
  • 2
  • 11
  • 21
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
25
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
  • 803
  • 1
  • 7
  • 21
24
votes
8 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
  • 7,684
  • 9
  • 47
  • 64
24
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
  • 8,635
  • 25
  • 92
  • 179
24
votes
1 answer

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.…
MCF
  • 1,020
  • 2
  • 10
  • 24
23
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,520
  • 3
  • 23
  • 27
21
votes
2 answers

Different font sizes in the same annotation of matplotlib?

I need to annotate a pylab rectangle with few data lines - which are of different length. Searching through the matplotlib documentation, and Googling, I could not find a way to give different parts of an annotation different sizes. The following…
user1850727
  • 349
  • 2
  • 4
  • 9
19
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
  • 15,775
  • 8
  • 80
  • 100
18
votes
4 answers

Pygame Drawing a Rectangle

Im 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. Thanks!
Jared
  • 280
  • 1
  • 2
  • 6
18
votes
2 answers

Check if two areas are in contact

Possible Duplicate: Finding the overlapping area of two rectangles (in C#) I have two areas identified by top left and bottom right corners (fig.1). In c#, how can I test if they are in contact (fig.2)?
A.Baudouin
  • 2,407
  • 2
  • 22
  • 26
18
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,411
  • 8
  • 46
  • 79
1
2 3
85 86