PDA

View Full Version : Clockwise/Anti-clockwise Polyline



csgohjmj
2004-08-07, 12:11 PM
Hi all;

Is there a way to determine whether a closed polyline is drawn clockwise or anticlockwise?
Thanks

csgoh
7-8-04

sinc
2004-08-07, 02:37 PM
Well, that doesn't really make sense for a polyline, since it can change its direction of curvature, and have line segments where "clockwise" doesn't make sense. But you can use vlax-curve-getFirstDeriv to get a direction vector showing the direction of the polyline at a given point, and vlax-curve-getSecondDeriv to get a direction vector to the radius of arc segments. (A direction vector is a 3D-coordinate; the vector is from (0,0,0) to the 3D-coordinate.) You can compare these two vectors to determine which direction curves are heading.

CAB2k
2004-08-07, 05:18 PM
;;===========================================================
;; PolyDir.LSP v1.0 (03-05-02) John F. Uhden, Cadlantic
;; This is freeware dedicated to Noah (?) and Cliff Middleton
;;
(defun C:PolyDir ( / @delta @cv_parse_list @polydir 2pi e ans)
;;-----------------------------------------------------------------------
;; This function returns the deflection angle (in radians) of two angles:
;;
(defun @delta (a1 a2)
(cond
((> a1 (+ a2 pi))
(setq a2 (+ a2 2pi))
)
((> a2 (+ a1 pi))
(setq a1 (+ a1 2pi))
)
)
(- a2 a1)
)
;;-------------------------------------------------------------
;; Function returns a list of 3D points from a continuous list
;; as returned by (vlax-safearray->list (vlax-variant-value X))
;;
(defun @cv_parse_list (data n / item new)
(foreach element (reverse data)
(setq item (cons element item))
(if (= (length item) n)
(setq new (cons item new) item nil)
)
)
new
)
(defun @polydir (e / ent etype object coords flag i p1 p2 p3 sum)
(cond
((/= (type e) 'ENAME) nil)
((not (vl-position (setq etype (cdr (assoc 0 (setq ent (entget e)))))
'("AECC_CONTOUR" "LWPOLYLINE" "POLYLINE")))
(prompt (strcat " Object selected is a(n) " etype))
)
((and (setq flag (cdr (assoc 70 ent)))(> (boole 1 16 flag) 0))
(prompt " Object selected is a 3DMESH")
)
(1 (setq object (vlax-ename->vla-object e)
coords (vlax-get object "Coordinates")
coords (@cv_parse_list coords (if (= etype "LWPOLYLINE") 2 3))
i 1
sum 0.0
)
(and
flag
(= (logand 1 flag) 1) ; closed
(setq coords (reverse (cons (car coords)(reverse coords))))
)
(repeat (- (length coords) 2)
(setq p1 (nth (1- i) coords)
p2 (nth i coords)
i (1+ i)
p3 (nth i coords)
sum (+ sum (@delta (angle p1 p2)(angle p2 p3)))
)
)
(if (minusp sum) "CW" "CCW")
)
)
)
(setvar "errno" 0)
(setq 2pi (* pi 2))
(while (/= (getvar "errno") 52)
(if (setq ans (@polydir (setq e (car (entsel "\nSelect a polyline: ")))))
(princ ans)
)
)
(princ)
)