# Is point InSide, ON and OutSide closed poligon

edited April 28
;********************************************************************
(defun GUKONT(To KON / i T1 T2 Ta Tb Ts PT LP W)
(defun YX0(YXo / )(list (car YXo) (cadr YXo)))

(defun NASEGMENTU(T1 T2 To d / Ui Do Di Y X W)
(setq T1 (yx0 T1) T2 (yx0 T2) To (yx0 To))
(if (or (< (distance To T1) d)(< (distance To T2) d))
(setq W T)
(progn
(setq Ui (- (angle T1 T2) (angle T1 To)) Do (distance T1 T2) Di (distance T1 To) Y (* Di (sin Ui)) X (* Di (cos Ui)))
(if (< (abs Y) d)(if (and (> X d)(< X (- Do d)))(setq W T)))
)
)
W
)

(defun STKORD0(YX D / )(strcat (rtos (car YX) 2 D) " " (rtos (cadr YX) 2 D)))

; W = 0 point is OutSide poligon
; W = 1 point is ON poligon
; W = 2 point is InSide poligon
(setq W 0 i 0 To (yx0 To) T1 (yx0 To) T2 (list (car To) (+ (cadr To) 1e6)) LP '())
(while (< i (- (length KON) 1))
(setq Ta (yx0 (nth i KON)) i (1+ i) Tb (yx0 (nth i KON)))
(if (= (nasegmentu Ta Tb To 0.001) T)
(setq W 1 i (length KON))
(progn
(setq PT (inters Ta Tb T1 T2))
(if (/= PT nil)(progn
(setq Ts (stkord0 PT 4))
(if (= (assoc Ts LP) nil)(setq LP (cons (list Ts PT) LP)))
))
)
)
)
(if (= W 0)
(if (/= (/ (length LP) 2.0) (fix (/ (length LP) 2.0)))(setq W 2))
)
W
)

;********************************************************************************
(defun UKONT(To KON / W)
; W = T if point is onli InSide closed contour
; W = nil if point is OutSide closed contour
(if (= (gukont To KON) 2)(setq W T))
W
)

;********************************************************************************
(defun UKONT0(To KON / W)
; W = T if point is InSide or ON closed contour
; W = nil if point is OutSide closed contour
(if (/= (gukont To KON) 0)(setq W T))
W
)