Jump to content

Polyline is going clockwise or counterclockwise


robierzo
 Share

Recommended Posts

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?

 

 

 

 

  • Like 1
Link to comment
Share on other sites

This has been asked many times over ... HERE is a function you can use. Do you know how to get points from a polyline?

  • Like 2
Link to comment
Share on other sites

@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.   

 

  • Like 1
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 by robierzo
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...