;; ! *************************************************************************** ;; ! 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 : rakesh.rao@4d-technologies.com ;; ! Web : www.4d-technologies.com ;; ! ****************************************************************************
(defun GE_WhatPoly (ptlist / nverts cnt area tmp pt1 pt2) (setq cnt 0 nverts (length ptlist) area 0.0 ) ;_ Endsetq (while (< cnt (1- nverts)) (setq pt1 (nth cnt ptlist) pt2 (nth (1+ cnt) ptlist) area (+ area (* (cadr pt1) (car pt2))) cnt (1+ cnt) ) ;_ Endsetq ) ;_ Endwhile (setq pt1 (nth (1- nverts) ptlist) pt2 (nth 0 ptlist) area (+ area (* (cadr pt1) (car pt2))) cnt 0 tmp 0.0 ) ;_ Endsetq (while (< cnt (1- nverts)) (setq pt1 (nth cnt ptlist) pt2 (nth (1+ cnt) ptlist) tmp (+ tmp (* (cadr pt2) (car pt1))) cnt (1+ cnt) ) ;_ Endsetq ) ;_ Endwhile (setq pt1 (nth 0 ptlist) pt2 (nth (1- nverts) ptlist) tmp (+ tmp (* (cadr pt1) (car pt2))) area (* 0.5 (- area tmp)) ) ;_ Endsetq (cond ((< area 0.0) (setq area -1)) ((> area 0.0) (setq area 1)) (t (setq area 0)) ) ;_ Endcond area ) ;_ Enddefun
|