Gian Paolo,
Yes there seems to be some inconsistencies when we are directly
on the line.
Maybe due to some rounding error in the onleft routine.
Thanks,
ymg
(defun PtInPoly_p1 (p l / i l p1 p2 v wn y)
;; Returns t if point p is strictly to the left of v1->v2 by ymg ;
(defun isleft (p v1 v2 / xp yp)
(setq xp (car p) yp (cadr p))
(minusp (- (* (- (cadr v1) yp) (- (car v2) xp)) (* (- (car v1) xp) (- (cadr v2) yp))))
)
;; Initialize the loop. ;
(setq p1 (car l)
y (cadr p)
wn 0
)
;; Loop through all edges of polygon. ;
(foreach p2 (cdr l)
(if (<= (cadr p1) y)
(if (> (cadr p2) y)
(if (isleft p p1 p2) (setq wn (1+ wn)))
)
(if (<= (cadr p2) y)
(if (not (isleft p p1 p2)) (setq wn (1- wn)))
)
)
(setq p1 p2)
)
(not (zerop wn));; Returns t if wn not equal to zero. ;
)
; // loop through all edges of the polygon
; for (int i=0; i<n; i++) { // edge from V[i] to V[i+1]
; if (V[i].y <= P.y) { // start y <= P.y
; if (V[i+1].y > P.y) // an upward crossing
; if (isLeft( V[i], V[i+1], P) > 0) // P left of edge
; ++wn; // have a valid up intersect
; }
; else { // start y > P.y (no test needed)
; if (V[i+1].y <= P.y) // a downward crossing
; if (isLeft( V[i], V[i+1], P) < 0) // P right of edge
; --wn; // have a valid down intersect
; }
; }
; return wn;
;}
(defun listpol (en / i p l)
(setq i (if (vlax-curve-IsClosed en)
(vlax-curve-getEndParam en)
(+ (vlax-curve-getEndParam en) 1)
)
)
(while (setq p (vlax-curve-getPointAtParam en (setq i (1- i))))
(setq l (cons (trans p 0 1 ) l))
)
)
(defun c:test (/ en l p)
(princ "\nSelect Polyline Under Test: ")
(setq en (car (entsel))
l (listpol en)
l (cons (last l) l)
)
(setvar 'PDSIZE -1.5)
(while (setq p (getpoint "\nPick a Point: "))
(if (ptinpoly_p1 p l)
(entmakex (list (cons 0 "POINT") (cons 10 p) (cons 62 1)))
(entmakex (list (cons 0 "POINT") (cons 10 p) (cons 62 7)))
)
)
(princ)
)