正时针,逆时针
http://www.4d-technologies.com/techcenter/geom/ge_whatpoly.lsp
info:
http://www.4d-technologies.com/techcenter/index.htm
http://www.faqs.org/faqs/CAD/autolisp-faq/part2/section-5.html
[23.6] How to REVERT a polyline direction?
- ;; ! ***************************************************************************
- ;; ! GE_WhatPoly
- ;; ! ***************************************************************************
- ;; ! Function : Find the direction of the polygon (if Cw or CCw)
- ;; ! Argument : ptlist - list of points forming the polygon
- ;; ! Returns :
- ;; ! 1 - clockwise
- ;; ! -1 - counterclockwise
- ;; ! 0 - Cannot be determined
- ;; ! Updated : September 19, 1998
- ;; ! (C) 1999-2004, Four Dimension Technologies, Bangalore
- ;; ! e-mail : [email]rakesh.rao@4d-technologies.com[/email]
- ;; ! Web : [url]www.4d-technologies.com[/url]
- ;; ! ****************************************************************************
- (defun GE_WhatPoly (ptlist / nverts cnt area tmp pt1 pt2)
- (setq
- cnt 0
- nverts (length ptlist)
- area 0.0
- )
- (while (< cnt (1- nverts))
- (setq
- pt1 (nth cnt ptlist)
- pt2 (nth (1+ cnt) ptlist)
- area (+ area (* (cadr pt1) (car pt2)))
- cnt (1+ cnt)
- )
- )
- (setq
- pt1 (nth (1- nverts) ptlist)
- pt2 (nth 0 ptlist)
- area (+ area (* (cadr pt1) (car pt2)))
- cnt 0
- tmp 0.0
- )
-
- (while (< cnt (1- nverts))
- (setq
- pt1 (nth cnt ptlist)
- pt2 (nth (1+ cnt) ptlist)
- tmp (+ tmp (* (cadr pt2) (car pt1)))
- cnt (1+ cnt)
- )
- )
- (setq
- pt1 (nth 0 ptlist)
- pt2 (nth (1- nverts) ptlist)
- tmp (+ tmp (* (cadr pt1) (car pt2)))
- area (* 0.5 (- area tmp))
- )
- (cond
- ((< area 0.0) (setq area -1) )
- ((> area 0.0) (setq area 1) )
- (T (setq area 0) )
- )
- area
- )
|