马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- [FONT=courier new]
- ;;;;;;测试程序
- (defun c:ccc(/ a a2 tf)
- (setq a1 '(670.759 584.45 0.0))
- (setq a2 (list '(560.248 748.043 0.0) '(812.045 748.043 0.0) '(812.045 503.352 0.0) '(560.248 503.352 0.0)))
- (setq tf (ER_point-in-poly a1 a2))
- (princ "\n答案:")
- (princ tf)
- (princ)
- )
- (defun ER_point-in-poly(xpt xdb / fhz mxb myb n i mx my nn p1 p2 p12 pxy a_line xpt1)
- (vl-load-com)
- (setq fhz 0
- mxb nil
- myb nil
- n (length xdb)
- i 0
- xdb (append xdb (list (car xdb)))
- )
- ;;(setq xpt1 (vlax-make-safearray vlax-vbdouble '(0 . 2)))
- ;;(setq xpt1 (vlax-safearray-fill xpt1 xpt))
-
- ; 判断点xpt是否在多边形上
- (while(< i n)
- (setq acadobject (vlax-get-acad-object)
- acadDocument (vla-get-activeDocument acadobject)
- mspace (vla-get-modelspace acaddocument)
- )
- (setq p1 (vlax-make-safearray vlax-vbdouble '(0 . 2)))
- (setq p1 (vlax-safearray-fill p1 (nth i xdb)))
- (setq p2 (vlax-make-safearray vlax-vbdouble '(0 . 2)))
- (setq p2 (vlax-safearray-fill p2 (nth (1+ i) xdb)))
- (setq a_line (vla-addline mspace p1 p2))
- (vla-put-Color a_line 9)
- ;;(setq p1 (nth i xdb) p2 (nth (1+ i) xdb))
- ;;(command "line" p1 p2 "" "chprop" (entlast) "" "c" 9 "")
- ;;;(princ "\nhhhhhhhhhhhhhhhh")(princ a_line )
- (setq p12 (vlax-curve-getclosestpointto a_line xpt1));;;;;这里出现error: bad argument type: 2D/3D point
-
- (entdel a_line)
- ;若xpt至某一边的距离为零,则xpt在多边形上,因计算误差,设10的-6次方为与零的比较误差
- (if (equal (distance xpt1 p12) 0.0 1e-6) (setq fhz 1 i n))
- (setq i (1+ i))
- )
- (if (/= fhz 1)
- ; 判断点xpt是否在多边形内
- (progn
- (foreach p12 xdb
- (setq mxb (append mxb (list (abs (- (car xpt1) (car p12)))))
- myb (append myb (list (abs (- (cadr xpt1) (cadr p12)))))
- )
- )
- (setq pxy (mapcar '+ xpt1 (list (* 2.0 (apply 'max mxb)) (apply 'min myb)))
- i 0 nn 0
- )
- (repeat n
- (if (inters xpt1 pxy (nth i xdb) (nth (1+ i) xdb)) (setq nn (1+ nn)))
- (setq i (1+ i))
- )
- (if (and (> nn 0) (/= nn (* (fix (/ nn 2.0)) 2.0))) (setq fhz 2))
- )
- )
- (setq fhz fhz)
- )
- [/FONT]
|