Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to find if Point inside Polygon or Block's Area?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
VB_Autocad_guy
4366 Views, 5 Replies

How to find if Point inside Polygon or Block's Area?

How would I go about this...

 

 if a two blocks or polygons are overlapping area? 

 

Anyone come across a good method or the algebraic formula for a funtion to tell me if a point is inside a polygon or block's area? 

 

5 REPLIES 5
Message 2 of 6


@VB_Autocad_guy wrote:

.... 

 if a two blocks or polygons are overlapping area? 

 

Anyone come across a good method or the algebraic formula for a funtion to tell me if a point is inside a polygon or block's area?


I don't know about Blocks, but if the polygon is a closed Polyline, the question has come up here before as to how you can determine whether a point is inside one of those.  Search the Discussion Group history.

Kent Cooper, AIA
Message 3 of 6
_Tharwat
in reply to: VB_Autocad_guy

Here is my codes to check if there  is any point in the selected Block ....

 

(defun c:TesT (/ ss i e)
  (vl-load-com)
;;;;;; Tharwat 20. Sep. 2011 ;;;;;;;
  (if (and (setq ss (car (entsel "\n Select Block :")))
           (eq (cdr (assoc 0 (setq e (entget ss)))) "INSERT")
           (setq i 0)
      )
    (progn
      (vlax-for x
                  (vla-item
                    (vla-get-blocks
                      (vla-get-activedocument (vlax-get-acad-object))
                    )
                    (cdr (assoc 2 e))
                  )
        (if (eq (vla-get-objectname x) "AcDbPoint")
          (setq i (1+ i))
        )
      )
      (if i   (alert (strcat "You have "  " < " (itoa i) " > "  " "  "Point(s) in the selected Block "  ))
        (alert "You have not Points in the selected Block !! ")
      )
    )
    (princ)
  )
  (princ)
)

 Tharwat

Message 4 of 6


@VB_Autocad_guy wrote:

How would I go about this...

 

 if a two blocks or polygons are overlapping area? 

 ....


Another approach you can use if they're both Polylines, which does not require you to determine whether any given location is inside either one, is to test whether they intersect:

 

(setq

  poly1 (vlax-ename->vla-object (car (entsel "\nSelect first Polyline: ")))

  poly2 (vlax-ename->vla-object (car (entsel "\nSelect second Polyline: ")))

)

 

Then,

 

(safearray-value (variant-value (vla-intersectwith poly1 poly2 acExtendNone)))

 

will return a list of coordinates if they intersect, and nil if they don't.  The list is all strung together in one, with the first three numbers representing one intersection, the next three another, etc.  If they merely touch at one spot such as a shared vertex location, the list will have three numbers in it.  If they coincide along an edge, it will have six.  If they overlap, they intersect more than once, and the list will have at least six, and possibly more, numbers.  But it requires that they actually do intersect, in 3D, not just visually from the point of view of the current view direction.

Kent Cooper, AIA
Message 5 of 6

; Marc'Antonio Alessi, Italy - http://xoomer.virgilio.it/alessi
;
; Function: ALE_Point_InsideCurveP
;
; Version 1.00 - 14/04/2004
;
; ImpPnt: must be a 3D point
;
; Command example:
(defun C:ALE_Point_InsideCurveP_Test ( / TstObj TstPnt)
  (if (setq TstObj (car (entsel "\nSelect curve: ")))
    (while (setq TstPnt (getpoint "\nPoint: "))
      (prin1 (ALE_Point_InsideCurveP TstPnt TstObj))
    )
  )
  (princ)
)
;
(defun ALE_Point_InsideCurveP (ImpPnt EntNam / VlaObj LstEnt EntAre OfsAre)
  (vl-load-com)
  (setq VlaObj (vlax-ename->vla-object EntNam))
  (cond
    ( (not (vlax-property-available-p VlaObj 'Area))
      (alert "It isn't possible to compute this object!")
    )
    ( (equal (vlax-curve-getclosestpointto VlaObj ImpPnt) ImpPnt 1e-10)
      (princ "\nPoint is on object! ")
    )
    ( (and
        (setq LstEnt (entlast))
        (not (command "_.OFFSET" 0.0000001 EntNam "_NONE" ImpPnt ""))
        (eq LstEnt (entlast))
      )
      (alert
        "It isn't possible to compute this point inside this object!"
      )
    )
    ( T
      (setq OfsAre 0.0   EntAre (vlax-get-property VlaObj 'Area))
      (while (setq LstEnt (entnext LstEnt))
        (setq
          OfsAre
            (+
              OfsAre
              (vlax-get-property (vlax-ename->vla-object LstEnt) 'Area)
            )
        )
        (entdel LstEnt)
      )
    )
  )
  (vlax-release-object VlaObj)
  (> EntAre OfsAre)
)

 

Marc'Antonio Alessi

http://alessi.xoom.it//alessi/Programmi.htm
(vl-string-translate "1234567890" "ie@mst.lan" "499825513610716")
2D Parametric for 2000-2013
Message 6 of 6


@VB_Autocad_guy wrote:

How would I go about this...

 

 if a two blocks or polygons are overlapping area? 

 

Anyone come across a good method or the algebraic formula for a funtion to tell me if a point is inside a polygon or block's area? 

 



Point inside a polygon is a well-known problem, with plenty of solutions in this group, on the Internet and in the computer graphics and computational geometry litterature.

 

Blocks are more difficult: an AutoCAD block is just a collection of drawing elements, which may be disjoint and don't necessarily have any meaningful area as such: for example, what would be the area of a block consisting of three non-intersecting, zero-thickness lines?

 

So, you need to generate from your block some kind of closed curve surrounding it that you can use for the checks, depends on your application what would be sufficient.

The coarsest approach would be using the bounding box of the block: if that says the point is outside, that is sure, but depending on the shape of your block there may be points that are outside the block itself, but inside the box.

- see vla-getBoundingBox

 

Next would be calculating the convex hull of the block: closer fit, but may still give false positives.

 

If that isn't enough, you'd need to create a contour curve for your blocks by hand, or programmatically if they have a really predictable structure.

 

--

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost