- (defun tb (ptn / mode p0 p1 p2 tmp rr)
- "点集逆时针凸包点"
- (setq ptn (vl-sort ptn '(lambda (x y) (< (cadr x) (cadr y))))
- p0 (car ptn)
- ptn (vl-sort (cdr ptn)
- '(lambda (x y) (< (angle p0 x) (angle p0 y)))
- )
- rr (angle p0 (car ptn))
- tmp (list p0)
- p1 p0
- mode t
- )
- (while mode
- (setq ptn (vl-remove-if '(lambda (x) (< (angle p1 x) rr)) ptn)
- ptn (vl-sort ptn '(lambda (x y) (< (angle p1 x) (angle p1 y))))
- p2 (car ptn)
- rr (angle p1 p2)
- ptn (vl-remove p2 ptn)
- ptn (if (not (member p0 ptn))
- (cons p0 ptn)
- ptn
- )
- )
- (if (not (equal p2 p0 1e-3))
- (setq tmp (cons p2 tmp)
- p1 p2
- )
- (setq mode nil)
- )
- )
- (reverse tmp)
- )
|