LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Do rectangles intersect?

I want to determine if two unfilled rectangles are overlapping. How can I do this?

The rectangles are defined initially by being drawn onto an IMAQ Vision window, from which I have the coordinates of the top left and bottom right corners. These are subsequently converted into overlays.

My thoughts were

1. Convert rectangles into separate pixel-sized points (how?). They are intersecting if there are points with common co-ordinates.

2.  Or, turn the rectangle into a contour (how?) and use Get Contour Info. This will also provide the pixel co-ordinates and I can identify if they are common for the two rectangles.

3. Perform an Intersection of the two rectangles (how?) and compare the the output with the inputs.

Any ideas?

0 Kudos
Message 1 of 3
(3,091 Views)

Rectangles are defined by 2 corners, so they are horizontal (vertical). There are a few cases with simple comarison: 2 in range functions with boolean logic. 

In general case (rotated rectangle) make a subvi for enterception of 2 sections (given their corners)

 

Solution 2: Merge overlays into separate images, AND them, search for non zero point. WIll work in very general case of variable shape areas of interest, but slower.

 

Alternative solution: Draw rectangles, display dialog window "Do these rectangles overlap?" =))

Message 2 of 3
(3,072 Views)

"intersect" is not necessary the same as "overlap". For example if a small rectangle is entirely contained inside a bigger rectangle, the would overlap, but the sides would not intersect.

If arbitrary rotation of the rectangles is not allowed, the problem seems quite trivial. Can you attach a simple example of your data?

0 Kudos
Message 3 of 3
(3,064 Views)