rectangle

How do I make two rectangles move out of eachother?

Let's say I have two rectangles overlapping each other like this... And I want them to end up like this... How would I calculate the position I need to add so that the rectangles move out of each other? Note: I did find this question but it doesn't tell me how to actually move the rectangles. Everyone's assuming I want to move th...

[WPF] How to draw a simple volume bar fast / databinding ?

I have a INotifyPropertyChanged derived class with a Volume property (float, 0.0f - 1.0f) that gets set on a fixed frequency (say 30fps). I'd like to draw a tiny volumebar displaying this in my window. I don't want to use a normal databound progressbar, I'd prefer something simpler (and faster :)). Is there a proper way to simply draw a...

Generate a random vector inside a rectangle but not a circle?

I have a rectangle, and a circle inside that rectangle (that sits around the center of the rectangle). I want to generate a random 2-component vector that falls inside the rectangle, but not the circle. How can I do it? Edit: I'd prefer a method that i can use to generate a vector that meets these constraints without brute-forcing it. ...

Get Rectangle of Image JPG and generate thumbnail in rectangle

I try explain: I have a JPG image (img A). This A.jpg has contents -colors, it's a picture of persons- and a one more little white rectangle (color white; the head of person is a white rectangle). I need get the position of rectangle in A.jpg. Then, I have another B.jpg image, more little; and I'll generate thumbnail of B.jpg , with R...

Finding a random WxH rectangle fitting in a MxN array region, where array[x][y] == number

I'm programming a game where a random map is generated whenever a new game is started. The game field is a MxN boolean array (true=ground, false=air.) From that array I calculate each connected free (air) regions, generating a new MxN int array where the int value is 0 if there's is ground, or the region number if it's free space (each f...

matlab - plot 2D rectangle with interpolated color

I want to plot a 2d rect (using the rectangle function is good enough for my needs), but with a linearly interpolated color, i.e at the bottom it should be red, at the top blue, and between the two there should be the linear interpolation of the two colors. How can I do this? ...

Calculate rectangle width and height from diagonal and rotation

Hello, I have a rotate rectangle and I know the size of the diagonal. I also know the angle used to rotate the rectangle. How can I calculate the width and height of the rectangle? For a sketch of the problem, see: ...

Move a rectangle around a canvas

I have a canvas in the middle of my application with controls around it. I have a socket that recieves Points and saves them in a list. I draw small 4x4 rectangles on the canvas for the number of points in my list.. say theres 4 points.. theres 4 rectangles. I want to be able to move the rectangles when the points change with code. is ...

Java Implementation of Rectangle Intersection Algorithm..?

Hi, I am interested in this algorithm: http://stackoverflow.com/questions/115426/algorithm-to-detect-intersection-of-two-rectangles but unable to implement it myself lacking even basic mathematical skills. I think I could understand it better once I can read the code. Does somebody perhaps have already an implementation or can quickly ...

Bounds rectangle of selected controls in wpf

Is there a simple way to find the rectangle (area and location) that would be required to cover a set of control?? VisualTreeHelper.GetDescandentBounds() works fine, but there are no overloaded methods where I can specify the controls that it should consider for finding the bounds rectangle. Any simple solution will be greatly appreciate...

Creating a Tree from a List of Rectangles

This may be a silly question, but nothing comes to mind straight away. Given a list R of 2D rectangles (x, y, w, h) arranged so that any given rectangle is either fully inside or fully outside any other, what's the most efficient way to determine the immediately enclosing rectangle p of each rectangle in R? Currently I sort R by y then x...

Line intersection with AABB Rectangle?

Preferably without using any kind of loop, as this'll be used in a game. I wish to intersect a line with a rectangle, of arbitrary size. But I also wish for the intersection point[s] to be returned. It's possible, I've done a little googling, but still have not worked it out. The line is defined using (x1,y1,x2,y2). The rectangle has ...

How to subtract a rectangle from another?

I'm trying to determine the working area of the desktop even when the taskbar is hidden. I have two Rectangles, the screen's bounds and the taskbar's bounds. I need to subtract the taskbar's bounds Rectangle from the screen Rectangle to determine the available working area of the desktop. Basically, I want to come up with Screen.Worki...

Merge (Boolean Union) rectangular regions with integer accuracy

Given any number of intersection, disjoint and touching rectangles, how to find the (multiple) outline polylines? Rectangles are defined in pixel coordinates so they have integer accuracy, but they may be thousands of units large. I really need numeric coordinates for the outlines, merging GDI regions won't do. I know I can simplify t...

Collision test between a triangle and a rectangle (AABB) in 2D

I've spent a good amount of time getting intersections working correctly between various 2D shapes (circle-circle, circle-tri, circle-rect, rect-rect - a huge thanks to those who've solved such problems from which I drew my solutions from) for a simple project and am now in the process of trying to implement an triangle-AABB intersection...

Creating custom components in Java AWT

I am trying to create a custom component using Java AWT or Swing which will be a rectangle with a number of components inside of it, including other rectangles. Something like this: ╔══════╗ ║ ┌┐ ║ ║ ├┘ ║ ║ ║ ╚══════╝ And this needs to be a component that I can preferably draw with one instruction. Something like myFrame.add(...

How do i get the coordinates of all four corners of a Rectangle?

How can i retrieve OR calculate the coordinates of the NW or SE corners of a Rectangle? I'm using Google Maps API v3 and I know there is the getBounds() method which returns the NE and SW coordinates of the rectangle. I need all four coordinates because KML 2.2 does not have a rectangle schema spec, it only has the polygon schema and ...

wpf how to inscrib rectangle in elipese

Hi I have quite a big problem. I draw elipse using Path element in wpf. My ellipse looks like that <Path x:Key="MainPath" Fill="{StaticResource DefaultBrush}" Stretch="Fill" Grid.RowSpan="2" Data=" M453.5,140.5C453.5,217.81986 352.0925,280.5 227,280.5 101.9075,280.5 0.5,217.81986 0.5,140.5 0.5,63.180135 101.9075,0.5 227,0.5 352.0925,0.5...

Maximum packing of rectangles in a circle

I work at a nanotech lab where I do silicon wafer dicing. (The wafer saw cuts only parallel lines) We are, of course, trying to maximize the yield of the die we cut. All the of die will be equal size, either rectangular or square, and the die are all cut from a circular wafer. Essentially, I am trying to pack maximum rectangles into a ci...

two questions about rectangle and canvas in silverlight 4

I have a rectangle on canvas. I can already moving this object using with mouse, but I can't find how can I resize it in runtime using mouse too? And second question, how can I programatically check positions of each objects (e.g rectangles) on the canvas? ...