Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to check if a 2dpoint is inside of a closed polyline?

7 views
Skip to first unread message

John Uhden

unread,
Mar 7, 2003, 10:15:31 PM3/7/03
to
Try this out...
;; Updated (03-07-03)
;; Given:
;;-------------------------------------------------------
;; Function to find or create an invisible ray VLA-Object
;; on Layer "0" an to create a global symbol $cv_ray.
;; It will leave the Ray object in the drawing to save time.
(defun @cv_ray ( / e ss)
(if (setq ss (ssget "X" '((0 . "RAY")(8 . "0")(60 . 1))))
(setq $cv_ray (vlax-ename->vla-object (ssname ss 0)))
(setq $cv_ray
(entmakex
(list
'(0 . "RAY")'(100 . "AcDbEntity")'(100 . "AcDbRay")
'(8 . "0")'(60 . 1)'(10 0.0 0.0 0.0)'(11 1.0 0.0 0.0)
)
)
$cv_ray (vlax-ename->vla-object $cv_ray)
)
)
)
;; And:
;;-------------------------------------------------
;; Function originated by Ken Alexander (03-05-03)
;; that is 10X faster than my @cv_parse_list,
;; to group data into triplets.
;; Thanks, Ken!
;;
(defun @cv_triple_up (old / new)
(while
(setq new (cons (list (car old)(cadr old)(caddr old)) new)
old (cdddr old)
)
)
(reverse new)
)
;; And:
;;-------------------------------------------------------------------
;; Function to determine if a point <PIQ> is inside a closed polyline
;; based on the number of intersections found between a ray whose
;; basepoint is the PIQ, and that PIQ is not one of the intersection
;; points.
;; Arguments:
;; PIQ = 3D Point in WCS
;; Outer = Outer Polyline VLA-Object
;; Returns:
;; either T (inside) or nil (on or outside)
(defun @cv_inside (PIQ Outer / Points)
(vl-load-com)
(and
(> (vl-list-length PIQ) 1)
(vl-every 'numberp PIQ)
(= (type Outer) 'VLA-Object)
(vlax-property-available-p Outer 'Closed)
(= (vla-get-closed Outer) :vlax-true)
(or $cv_ray (@cv_ray))
(or (vlax-put $cv_ray "Basepoint" PIQ) T)
(setq Points (vlax-invoke Outer "IntersectWith" $cv_ray acExtendNone))
(setq Points (@cv_triple_up Points))
(= (rem (length Points) 2) 1)
(not (equal PIQ (vlax-curve-getclosestpointto Object PIQ) 1e-11))
)
)

;; Then:
;; ... define your point and Outer object ...
(setq Inside (@cv_inside PIQ Outer))

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"mvicol" <mvi...@dmhi.ct.ro> wrote in message
news:f14bc...@WebX.maYIadrTaRb...
> Hello!
> I need the algorithm for checking if a 2d point is inside or outside of a
closed 2d polyline!
> Or at list an ideea...how can I decide....?
>
> Thank you!
>

R. Robert Bell

unread,
Mar 7, 2003, 11:05:03 PM3/7/03
to
I love how you use (entmakex) to make sure the ray isn't permanent! I *was*
surprised that you didn't use ActiveX to create the ray if it didn't exist,
until I glommed on to why you used (entmakex).

--
R. Robert Bell, MCSE
www.AcadX.com


"John Uhden" <juh...@cadlantic.com> wrote in message
news:25065A4BD4F65A40...@in.WebX.maYIadrTaRb...

0 new messages