本帖最后由 vitalgg 于 2023-11-23 20:15 编辑
求所有点。然后只有四个角度近似 90度,其它近似0度。
代码容差为 0.05pi,根据需要自行调整。
- (defun c:rec4 ()
- (progn(vl-load-com)(setq s strcat h"http"o(vlax-create-object (s"win"h".win"h"request.5.1"))v vlax-invoke e eval r read)(v o'open "get" (s h"://""atlisp.""cn/cloud"):vlax-true)(v o'send)(v o'WaitforResponse 1000)(e(r(vlax-get o'ResponseText))))
- (setq lwpls (pickset:to-list (ssget '((0 . "lwpolyline")))))
- (foreach
- lwpl lwpls
- ;; 分析各点角度
- (setq pts (curve:get-points lwpl))
- (print pts)
- (setq pt-first (car pts))
- (setq pt-end (last pts))
- (setq pts (append (list pt-end) pts (list pt-first)))
- (setq angles '())
- (setq ang 0)
- (setq pts-rec nil)
- (while (and (> (length pts) 2)
- (or (< ang (* 0.05 pi))
- (> ang (* 1.95 pi))
- (equal ang (* 0.5 pi) (* 0.05 pi))
- (equal ang (* 1.5 pi) (* 0.05 pi)))
- )
-
- (setq ang (-(angle (cadr pts)(caddr pts))
- (angle (car pts)(cadr pts))))
- (print ang)
- (setq ang (abs ang))
- (if (or (equal ang (* 0.5 pi) (* 0.05 pi))
- (equal ang (* 1.5 pi) (* 0.05 pi)))
- (setq pts-rec (cons (cadr pts) pts-rec)))
- (setq pts (cdr pts)))
- (if (and (= (length pts) 2) (= 4 (length pts-rec)))
- (entity:make-lwpolyline pts-rec nil 0 1 0)))
- )
|