robierzo Posted January 12, 2022 Posted January 12, 2022 Hello. I need to know if a closed polyline is going clockwise or counterclockwise. Thanks Quote
Steven P Posted January 12, 2022 Posted January 12, 2022 How far have you got with this? I guess if you use entget for the user to select the polyline and then entlist you could use what was discussed below (Dan2047 or Mhupp) to give you a list of all the assoc's umber 10. all the points from the polyline Once you have them I think it is just maths to work out what direction each segment is going in.. though I haven't thought how to tell if a closed polyline is clockwise or anticlockwise yet. Maybe have a go at getting the list of polyline points and see if someone can take it from there? 1 Quote
ronjonp Posted January 12, 2022 Posted January 12, 2022 This has been asked many times over ... HERE is a function you can use. Do you know how to get points from a polyline? 2 Quote
X11start Posted January 13, 2022 Posted January 13, 2022 In this forum ... https://www.cad3d.it/forum1/discussione/cambiare-lordine-dei-vertici-di-una-polilinea.9096/ you can find CHVERT.LSP to change first point and/or reverse polyline. 1 Quote
lrm Posted January 13, 2022 Posted January 13, 2022 @ronjonp Lee Mac's routine determines CW or CCW from three points. Use it assumes the polyline is a convex shape. If the polyline has a concave segment this may yield the wrong direction. 1 Quote
Steven P Posted January 13, 2022 Posted January 13, 2022 That's right, but this is perhaps where the OP needs to help out with some thinking maybe? Haven't checked but it probably needs a combination of each segment direction and length weighted somehow and added together to get an overall direction. Imagine rectangle with a concave segment cut into it - for arguments the concave segment is made from short lines. If you add up all the directions then the short lines of the concave section will be more than the directions of the other 5. +ve multiplier for line length clockwise and -ve multiplier line length for anticlockwise, then add up all the line lengths? -ve and it is mostly anticlockwise, +ve and clockwise perhaps 1 Quote
BIGAL Posted January 13, 2022 Posted January 13, 2022 One by Kent Cooper is for closed plines get area then use VLAoffset, test (< area1 area2) a simple is it clockwise. If area goes bigger its CCW. For direction on a open PLINE I use pick an end so know direction to imply. 1 Quote
Stefan BMR Posted January 14, 2022 Posted January 14, 2022 Take a look at the function clockwise-p in this post. 1 Quote
robierzo Posted January 14, 2022 Author Posted January 14, 2022 (edited) Thank you all. In the end I have done this, which works in most cases. If they are very rare polylines, it may fail. To find the solution I use an auxiliary line that I delete at the end of the sequence. Thanks!!!!! (defun c:sentido () (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)) Space (if (= (getvar "CVPORT") 1) (vla-get-PaperSpace AcDoc) (vla-get-ModelSpace AcDoc) ) ) (while (setq poli_cerrada (entsel "\nDesigna una LwPolyline cerrada: ")) (setq coordenadas nil) (setq nombre_poli (car poli_cerrada)) (setq lista_poli (entget nombre_poli)) ;coordenadas poly (foreach n lista_poli (if (= (car n) 10) (setq coordenadas (cons (cdr n) coordenadas))) ) (setq coordenadas (reverse coordenadas)) (setq ptm (mapcar '(lambda (x y) (/ (+ x y) 2)) (car coordenadas) (cadr coordenadas))) (setq pt_izda (polar ptm (+ (angle (car coordenadas) (cadr coordenadas)) (/ pi 2)) 0.5)) ;centroide (setq obj (vlax-ename->vla-object nombre_poli)) (setq reg (vlax-invoke Space 'addRegion (list obj))) (setq centroide (vlax-get (car reg) 'Centroid)) (entdel (entlast)) ;creamos linea auxiliar (entmake (list '(0 . "LINE") '(100 . "AcDbEntity") '(100 . "AcDbLine") (cons 10 centroide) (cons 11 pt_izda) ) );fin entmake (setq aux (vlax-ename->vla-object (entlast))) (setq interseccion (vla-intersectWith aux obj AcExtendNone)) (if (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value interseccion))))) (princ "\nSentido Horario") (princ "\nSentido AntiHorario") ) (entdel (entlast)) );fin while ) Sentido polilinea.dwg Edited January 14, 2022 by robierzo Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.