本帖最后由 chlh_jd 于 2011-8-5 21:03 编辑
就多边形而言,我一直用狂刀前辈的代码;期待能早日见到支持各类型曲线的纯LISP版或调用ACAD自身的版本 - ;;;判断点是否在封闭多边形内 .
- ;;;Function : judge a point location with polygon
- ;;;Arg : pt -- a point
- ;;; pts -- points of polygon
- ;;; eps -- allowance
- ;;;return :
- ;;; -1 -- out of polygon , 0 -- at , 1 -- in
- (defun pipl?(pt pts eps / is at a)
- ;; by 狂刀
- ;; Edit by GSLS(SS) 2011.03.28
- ;; Solved the problem : if a point at the given polygon , it perhap return T or NIL .
- (setq pt(trans pt 0 0)pts(mapcar(function(lambda(x)(trans x 0 0)))pts)Eps(abs Eps))
- (if(equalmember pt pts eps)0
- (progn(setq is(equal PI (abs(apply(function +)(mapcar(function(lambda (x y / a)
- (setq a (rem (- (angle pt x) (angle pt y)) PI))
- (if(equal (+(distance pt x)(distance pt y))(distance x y)Eps)(setq at T))a));_(check-pt (list x y))
- (cons (last pts) pts) pts))) eps))(cond (at 0)(is 1)(T -1)))))
- (defun equalmember (e lst tor /)
- (apply (function or)
- (mapcar (function (lambda (x) (equal x e tor))) lst)
- )
- )
|