Questions tagged [rectangles]

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

1277 questions
17
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,042
  • 6
  • 45
  • 76
16
votes
1 answer

What is the best way to convert from a RectF to a Rect in Android?

I would like to convert from a RectF to a Rect in Android. Currently I have: RectF rectF = new RectF(); rectF.set( ... some values ... ); ... Rect rect = new Rect((int)rectF.left, (int)rectF.top, …
superdave
  • 1,444
  • 13
  • 26
16
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
  • 2,908
  • 4
  • 19
  • 39
14
votes
4 answers

Why there is a gap between div and rotated div (triangle)

I am trying to do this shape in HTML/CSS for my mobile app: https://embed.plnkr.co/9k8jbJyzUiSMSoSHlOti/ .boundary { width: 100.13723%; padding-bottom: 5.24078%; position: relative; overflow: hidden; background-color:…
sophie
  • 166
  • 3
14
votes
3 answers

What's a good, simple, 2D rectangles-only collision detection algorithm?

I'm designing a collision detection game tutorial for young adults, so I want this to be as simple as possible to make it easier to explain. The requirements are very simple. The world is 2D and contains only rectangles (of arbitrary sizes). BSP and…
Alvin Smith
  • 141
  • 1
  • 4
14
votes
4 answers

Algorithm for best fit rectangle

I'm looking for an algorithm to do a best fit of an arbitrary rectangle to an unordered set of points. Specifically, I'm looking for a rectangle where the sum of the distances of the points to any one of the rectangle edges is minimised. I've…
SmacL
  • 21,621
  • 10
  • 89
  • 143
14
votes
3 answers

Is there a circle class in Java like the Rectangle class

Hey I was writing a quick program and something came across where I need to use a circle for collision detection. But as far as I know, there is only the Rectangle class that has the .intersects(Point p) method. Is there anything like a circle that…
user1871085
  • 159
  • 1
  • 1
  • 8
13
votes
5 answers

How to divide a set of overlapping ranges into non-overlapping ranges?

Let's say you have a set of ranges: 0 - 100: 'a' 0 - 75: 'b' 95 - 150: 'c' 120 - 130: 'd' Obviously, these ranges overlap at certain points. How would you dissect these ranges to produce a list of non-overlapping ranges, while retaining…
Ron Eggbertson
  • 185
  • 1
  • 6
13
votes
2 answers

How to draw a rectangle inside a rectangle using svg?

I am trying to draw a rectangle inside a rectangle using svg, but I am not seeing the inner rectangle. Could somebody help me what is the mistake I am doing ?? The code is as below.

My first SVG

sakthisundar
  • 3,142
  • 3
  • 14
  • 28
13
votes
1 answer

how to add a transparent rectangle to a R boxplot (plot)?

I have a simple boxplot for my data using R .. boxplot (Error~Code, DataFrame1, xlim = c(0, 27), xlab="set Code",ylab="Error", boxwex=0.75, cex.axis=0.3) and I would like to draw a transparent rectangle all over the plot between 2 defined…
Leo...
  • 281
  • 2
  • 4
  • 14
12
votes
3 answers

Optimum set of dirty rectangles

I'm looking for an algorithm here, independent of specific programming language. The problem: We have a 2-dimensional display area (think simple buffer of pixels). Periodically, some of the pixels are changed. We need to find a set of …
Clay Fowler
  • 2,031
  • 13
  • 14
12
votes
2 answers

Convert Rect to RectF

Whats the best way to convert a Rect variable to a RectF one? I am unable to cast it. RectF rect = (RectF) currentRect; //produces an error
industrychanger
  • 543
  • 1
  • 8
  • 20
12
votes
3 answers

How to draw a rounded rectangle (rectangle with rounded corners) with OpenCV?

How can I draw a rectangle with rounded corners in OpenCV? I know that the functions ellipse() and line() can be simply put together to draw it. I just wonder if someone has done it before and has put it in a proper function so I can use it? Ideally…
Kenyakorn Ketsombut
  • 1,935
  • 1
  • 21
  • 41
12
votes
2 answers

Finding the overlapping area of two rectangles (in C#)

Edit: Simple code I used to solve the problem in case anyone is interested (thanks to Fredrik): int windowOverlap(Rectangle rect1, Rectangle rect2) { if (rect1.IntersectsWith(rect2)) { Rectangle overlap =…
Evan
  • 4,250
  • 10
  • 37
  • 58
12
votes
5 answers

Libgdx - How to draw filled rectangle in the right place in scene2d?

I am using scene2d. Here is my code: group.addActor(new Actor() { @Override public Actor hit(float arg0, float arg1) { return null; } @Override public void draw(SpriteBatch batch, float arg1) { batch.end(); …
Aleksandrs
  • 1,346
  • 1
  • 11
  • 33
1
2
3
85 86