merging rectangles

  • Thread starter Thread starter aameradam
  • Start date Start date
A

aameradam

Guest
Here's what I'm trying to do:

Given two rectangles A & B, I want to merge rectangles A & B such that the merged Rectangle C contains both rectangle A & B. (A & B are two overalapping rectangles).

I know this is more a logic question than a Access question....but I'm trying to do this in Access....any help will be appreciated.
 
I get the feeling I'm going to regret replying to this but here goes...

1. So you have 2 rect's
2. You need a 3rd rect that has an area equal to the sum of the areas of the other two rect's
3. The height(l) to width(w) ratio of the 3rd rect should be and avg of the other two rect's

???
 
Last edited:
I tried to post this a few minutes ago and something crashed.

OK, rectangles have four relevant properties.

A rectangle's point of reference is its upper left corner. The position of the rectangle with respect to its enclosing window is at its .Top, .Left corner. The OPPOSITE corner is .Top+.Height, .Left+Width

So you get A.Top, A.Left, (A.Top+A.Height), (A.Left+A.Width) ... and the same for B

Now find the minimum of the .Tops and the minimum of the .Lefts, then find the maximum of the (.Top+.Height) and of (.Left+.Width)

Form a rectangle with the minimum .Top, .Left corner and the maximum (.Top+.Height), (.Left+.Width) corner.

That's it, that's your enclosing rectangle.
 
No....I guess this is best explained by a picture. In the attached picture diagram 1 represents two overlapping rectangles in black and yellow. I need to get the merged rectangle between these two rectangles as represented in Figure 2. Figure 2 shows a merged rectangle in blue. This is what I'm trying to get to.

Again, any help is appreciated.
 

Attachments

  • diagram.jpg
    diagram.jpg
    19.1 KB · Views: 190
What are the givens values? I assume you'll get the height and width of each rectangle. Then you'll need to have some other pc of common data...

Or maybe you're using relative coordinates to begin with?
 
Last edited:
So you need nearly what Doc Man suggested:

Still the min of the Lefts and max of (Left + Width)s, but you need the max of the Tops and min of the (Top + Height)s.

I don't think I'd describe what you've got as a "merged rectangle" though...

Dave
 
See attached:

Is this what's happening?
 

Attachments

  • rect.GIF
    rect.GIF
    2.3 KB · Views: 179
merged rectangles

Yeah, I may be describing it incorrectly. The dataset for each rectangle will be two sets of coordinates: upperleft coordinate and bottom-right coordinate:

for example:
Rectangle A
Upperleft Corrdinate = 1,7
Bottomright Coordinate = 8,5

Reactanle B
Upperleft Coordinate = 5,6
Bottom-Right Coordinate = 12,3

Resultant Merged Rectangle:
Upperleft Coordinate = 1,6
BottomRight Coordinate = 12,5
 
So what values are you going to have to start with and what values are you going to have to come up with. Seems you just answered your own question if you're given the values for rectangles 1 & 2 and you need to find the values for rectangle 3 ....
 
merged rectangles

yes...but I need to know how to find the values for rectangle 3 given the values of rectange 1 & 2 programatically...
 
myBoxA.Top
myBoxA.Left
myBoxA.Width
myBoxA.Height

myBoxB.Top
myBoxB.Left
myBoxB.Width
myBoxB.Height

myBoxC.Top = myBoxB.Top
myBoxC.Left = myBoxA.Left
myBoxC.Width = myBoxB.left + myBoxB.width
myBoxC.Height = myBoxA.top + myBoxA.height

???
 

Users who are viewing this thread

Back
Top Bottom