rectangles

How to calculate distance between two rectangles? (Context: a game in Lua.)

北慕城南 提交于 2019-11-29 01:21:35
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 ensure certain rectangles aren't too close to each other -- this is needed because maps become unsolvable if the rectangles get into certain close-distance position, as a ball needs to pass between them. Speed isn't a huge issue as I don't have many rectangles and the map is just generated once per level. Previous links I found on StackOverflow are

How to draw a rounded rectangle in c#

久未见 提交于 2019-11-29 00:58:59
问题 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 Bitmap DrawRoundedRectangle(Bitmap Image, Color BoxColor, int XPosition, int YPosition, int Height, int Width, int CornerRadius) { Bitmap NewBitmap = new Bitmap(Image, Image.Width, Image.Height); using (Graphics NewGraphics = Graphics.FromImage

Qt drawing a filled rounded rectangle with border

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 23:11:07
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 - fillRect and drawRect and drawRoundedRect . I have tried them, they don't work like I want to. There is no method like fillRoundedRect . Which means that I can draw a rounded rectangle but it won't be filled with the color I want. How do I do it? And also, I read that due to some aliasing problems, the corners are often rendered as unequal. How do I set

Finding an axis-aligned rectangle inside a polygon

你离开我真会死。 提交于 2019-11-28 05:29:20
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 may also have holes, but any pointers to algorithms that only work for convex or simple polygons would be helpful too. In my implementation, intersection testing for sides is fairly cheap, but "point in polygon" tests are expensive, so ideally should be minimised. http://cgm.cs.mcgill.ca/~athens/cs507/Projects/2003/DanielSud/ Has an algorithm for

Merging multiple adjacent rectangles into one polygon

梦想的初衷 提交于 2019-11-28 05:03:31
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 units) Problem : I have a list of rectangles ( units ), defined by pairs of points – [[lefttop_x;lefttop_y];[rightbottom_x;rightbottom_y]] – and I want to merge them into polygons, so I can properly style them (which I will then render via Canvas/SVG/VML/Raphael.js). Units are always rectangles Units have different sizes Units are always adjacent (there is no

Is there a circle class in Java like the Rectangle class

笑着哭i 提交于 2019-11-28 02:46:46
问题 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 I could use the same way? 回答1: There is a class called Ellipse2D in the java.awt.geom package that you can use, since it has some methods that appears to be what you're looking for. An ellipse with a width equal to its height is a circle. One of

How to check intersection between a line and a rectangle?

让人想犯罪 __ 提交于 2019-11-28 00:11:06
问题 The title says it all, Ive been searching around and couldnt find anything that was straight and to the point. How would I take a line with points (x1,y1) & (x2, y2) and check its intersection between a rectangle (xR,yR)? I saw in the Line2D package that there were some intersection methods but not sure how to set it all up. Can someone show me a correct way of setting it up to check for an intersection (collision)? 回答1: Using the available classes from the 2D Graphics API. Rectangle r1 = new

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

这一生的挚爱 提交于 2019-11-27 16:10:56
问题 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 = Rectangle.Intersect(rect1, rect2); if (overlap.IsEmpty) return overlap.Width * overlap.Height; } return 0; } Original Question: I'd like to know a quick and dirty way to check if two rectangles overlap and if they do calculate the area of the overlap. For curiosities sake I'm interested in

How to calculate distance between two rectangles? (Context: a game in Lua.)

本秂侑毒 提交于 2019-11-27 15:48:17
问题 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 ensure certain rectangles aren't too close to each other -- this is needed because maps become unsolvable if the rectangles get into certain close-distance position, as a ball needs to pass between them. Speed isn't a huge issue as I don't have many

Rectangles Covering

一世执手 提交于 2019-11-27 12:55:56
问题 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 need to sort the rectangles by their left side (it can be done in O(n log n) time), and then use a vertical sweeping line. +------------------------------------------------------------> x |O | +----+ | +---------+ | | | | ++----+--+ | | | +-++----+-+| |