Andrea,
The "isleft" test normally should not be too sensitive to
how far from zero you are.
Although it is a cross-product, you are multiplying only
the difference between coordinates.
Rojomp,
It could be a little faster if we would modify the isleft
to get 6 parameters (xp yp x1 y1 x2 y2) since
we already do some of the car and cadr in the calling
routine.
Beware! I did not test any of the code below,
just did the change on the fly!
(defun isleft
(xp yp x1 y1 x2 y2
) (minusp (- (* (- y1 yp
) (- x2 xp
)) (* (- x1 xp) (- y2 yp))
)
)
)
;;============================================================================;
;; ;
;; PtInPoly_p(): Winding number test for a point in a polygon ;
;; ;
;; Input: p = a point ;
;; l = List of points forming the polyline ;
;; ;
;; Return: t, if point is in polyline. (wn is not 0) ;
;; ;
;; Original code in C++ by Dan Sunday ;
;; See: http://geomalgorithms.com/a03-_inclusion.html ;
;;============================================================================;
(defun PtInPoly_p
(p l
/ xp yp x1 y1 x2 y2 wn
)
;; Returns t if point p is strictly to the left of v1->v2 by ymg ;
(defun isleft
(xp yp x1 y1 x2 y2
) (minusp (- (* (- y1 yp
) (- x2 xp
)) (* (- x1 xp) (- y2 yp))
)
)
)
wn 0
)
;; Loop through all edges of polygon. ;
(if (isleft xp yp x1 y1 x2 y2
) (setq wn
(1+ wn
))) )
(if (isleft xp yp x2 y2 x1 y1
) (setq wn
(1- wn
))) )
)
)
)
ymg