(vl-load-com)
(cond
((setq pline (car (entsel "\nPolyline: ")))
;; NO error checking .. assume a lwpoly is selected!
(setq oPline (vlax-ename->vla-object pline)
;; pick point to investigate
aPt (getpoint "\nPick point: ")
;; initialize starting angle for "ray"
someAngle 0.0
;; set delta angle for rotation of "ray"
delta (/ (* 2 pi) 8)
)
(cond
;; start by making a "ray" shooting out from aPt
;; (should use vla-add but what the heck)
;; (should also use a real RAY and manipulate
;;unit vector .. but what the heck)
((entmake (list '(0 . "LINE") (cons 10 aPt)
(cons 11 (polar aPt 0.0 100.0))
)
)
(setq oline (vlax-ename->vla-object (entlast)))
(repeat 8
(cond
;; get intersection points with pline and "ray"
((setq ints (vla-intersectwith oPline oLine acExtendNone))
;; should be using vlax-...-u-bounds and all that to check
;; safearray (but what the heck, this is quicker to write)
(if (not (vl-catch-all-error-p (setq ints (vl-catch-all-apply
'vlax-safearray->list
(list (vlax-variant-value ints)))
)
)
)
;; just put nil for uneven number of hits and T for even
(setq clst (cons (not (zerop (rem (length ints) 2.0))) clst))
)
)
)
;; pause to see the "ray" move around
(while (not (grread nil 10)))
;; move endpoint of "ray"
(vla-put-endpoint oLine (vlax-3D-point
(polar aPt (setq someAngle (+ delta someAngle)) 100.0)
)
)
)
(vla-delete oLine)
(vlax-release-object oLine)
(vlax-release-object oPline)
)
)
)
)
;; .. and a lazy decoding of result:
(cond ((not (member 'nil clst))(princ "Inside"))
((not (member 'T clst))(princ "Outside"))
((princ "Probably on an edge or vertex")))
(terpri)
clst
)
info from:
https://www.theswamp.org/index.php?topic=1890.0 论坛小白,请问代码是用什么写的,我复制到记事本段落格式全变了。
页:
1
[2]