I think something like this [untested] should work on orthogonal rectangles with the same Z
extrusion direction [whether or not they're at the same Z elevation]. Otherwise [for example
non-orthogonal, especially if not rotated to the same angle], I'd have to think about what the
complications would be. I haven't really worked with the getBoundingBox or safearray things before,
so there might be a simpler way to go about it, and I hope I got the syntax right. You might need a
(vl-load-com) first, too.
(setq
rectA (vlax-ename->vla-object (car (entsel "Select Rectangle A: ")))
rectB (vlax-ename->vla-object (car (entsel "Select Rectangle B: ")))
); end setq
(vla-getBoundingBox rectA 'minA 'maxA); set corners to safearray variables
(vla-getBoundingBox rectB 'minB 'maxB)
(setq
llA (vlax-safearray->list minA); convert safearrays to regular point lists
urA (vlax-safearray->list maxA)
llB (vlax-safearray->list minB)
urB (vlax-safearray->list maxB)
); ent setq
(cond
((and ; if lower left corner of A is to upper right of lower left corner of B, etc.
(= (cdr (reverse (mapcar '> llA llB))) '(T T)); removes Z to check only X and Y
(= (cdr (reverse (mapcar '< urA urB))) '(T T))
); end and
(alert "Rectangle A is INside Rectangle B.")
); end A-inside-B test
((and
(= (cdr (reverse (mapcar '< llA llB))) '(T T))
(= (cdr (reverse (mapcar '> urA urB))) '(T T))
); end and
(alert "Rectangle A is OUTside Rectangle B.")
); end A-outside-B test
(T (alert "Rectangles A and B overlap or {at least partially} coincide."))
); end cond
If they're always *Polyline* rectangles, and always orthogonal, it might be done more briefly,
calculating lower left and upper right corners from their entity data. The above [assuming it
actually works] has the advantage that it should also work if the rectangles are Blocks or [2D]
Solids or 3DFaces or Traces or Mlines.
--
Kent Cooper
skin wrote...
how to compare if one rectangle is inside other one?
how to get coordinates from rectangles and compare them?
result should be: A is inside B, A is outside B and A&B are overlapping...