Results 1 to 7 of 7

Thread: Polyline clockwise

  1. #1
    Login to Give a bone
    0

    Default Polyline clockwise

    Hi.
    Someone knows a lisp routine that analyzes a polyline, determine in what sense it is, and if it is counterclockwise, change it clockwise.
    Thank you for your help.

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: Polyline clockwise


  3. #3
    Login to Give a bone
    0

    Default Re: Polyline clockwise

    Good morning.
    Thank you Tom.
    The routine of marko_ribar is good.
    I'm looking for something simpler: Select polyline, analyze the orientation, if the orientation is clockwise, finish the routine, if the orientation is counterclockwise, change it to clockwise.
    Any ideas?
    Again, thank you very much.

  4. #4
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: Polyline clockwise

    It's not like there's a property or something, you're not going to find anything much simpler. What purpose are you needing this for? What difference does it make?

  5. #5
    Login to Give a bone
    0

    Default Re: Polyline clockwise

    Tom, thanks for your help.
    I have a lisp routine that calculates a table of technical data: azimuth and distance. Calculate these data depending on the direction of the polyline, it can be clockwise or counterclockwise,
    I always try to do it clockwise. For which I need to add to the main lisp a lisp that can work as a function and convert the polylines counterclockwise to clockwise.

    This is the lisp I have:


    ;********************************************************************
    (DEFUN massoc (key EntData / x nlist)
    (FOREACH x EntData
    (IF (EQ key (CAR x))
    (SETQ nlist (CONS (CDR x) nlist))
    ) ;_ end of if
    ) ;_ end of foreach
    (REVERSE nlist)
    )

    ;********************************************************************
    (DEFUN c:TDL (/ ent vertices-lista poly poly-data nv aa pp hn rotu
    vv vi cont conj aa pp ent
    MSC MSC1 MSC2 HT FSC2 FSC3 FSC4
    XD tp PO cont cont1 X Y X1
    Y1 P1 P2 ang-rad ang-dec dist
    punto control control1 w ww
    )
    (graphscr)
    (setvar "cmdecho" 0)
    (setvar "dimzin" 1)
    (setq osm (getvar "osmode"))
    (setvar "osmode" 9)
    (setq angbase (getvar "angbase"))
    (setvar "angbase" (* pi 0.5))
    (setq angdir (getvar "angdir"))
    (setvar "angdir" 1)
    (setvar "orthomode" 0)
    (setvar "clayer" "0") ;capa cero
    (command "color" "bylayer")
    (command "OSNAP" "OFF" "")
    ;*********************************************************************
    (command "layer" "N" "Lindero" "c" "5" "Lindero" "")
    (setq poly (car (entsel "\nSeleccione la Polilinea 2D: ")))
    (command "area" "o" poly)
    (setq aa (getvar "area"))
    (setq pp (getvar "perimeter"))
    (setq poly-data (entget poly))
    (setq vertices-lista (massoc 10 poly-data))
    ;**********************************************************************
    (setq nv (length vertices-lista))
    (setq control (length vertices-lista))
    (setq control (- control 1))
    ;**********************************************************************
    (if (= esc nil)
    (setq esc 1000)
    )
    (setq hn (rtos esc 2 0))
    (setq rotu (strcat "Escala 1:" hn " "))
    (setq hn (getreal rotu))
    (if (/= hn nil)
    (setq ESC hn)
    )
    ;**********************************************************************
    (setq MSC (/ 1000 ESC))
    (setq MSC1 (/ ESC 1000))
    (setq MSC2 (/ 1000 ESC))
    (setq HT (/ 2.0 MSC))
    (setq FSC2 (* 20.0 MSC1))
    (setq FSC3 (* 50.0 MSC1))
    (setq FSC4 (* 70.0 MSC1))
    (setq XD (* (/ ESC 1000) 1.5))
    (setq tp (/ 1.0 MSC2))
    ;-----------------------------------------------------
    (setq w 65)
    ;-----------------------------------------------------
    (setq vi 1)
    (setq vv vi)
    (setq stx 0) (setq sty 0)
    (terpri)
    (setq PO (getpoint "Donde quiere la Tabla: "))
    (setq CX1 (NTH 0 PO))
    (setq CY1 (NTH 1 PO))
    (setq CYT1 (- CY1 (* 13.5 MSC1)))
    ;**********************************************************************
    (command "chprop" poly "" "LA" "Lindero" "")
    (command "_layer" "m" "vertice" "C" "1" "" "")
    (foreach vertice vertices-lista
    (command "_circle" vertice tp)
    )
    (command "layer" "m" "Identificador" "c" "3" "" "")
    (foreach vertice vertices-lista
    ; (command "text" "j" "r" vertice ht "90" (rtos vv 2 0))

    (command "text" "j" "r" vertice ht "90" (chr w))

    (setq vv (+ vv 1))
    ;-----------------------------------
    (setq w (+ w 1))
    ;-----------------------------------
    )
    ;**********************************************************************
    (setvar "clayer" "0") ;capa cero
    (command "color" "bylayer")
    (setq cont 0)
    (setq cont1 1)
    ;*************************************************
    (setq w 65)
    (setq ww 66)
    ;*************************************************
    (setq vert 1)
    (setq ver1 2)
    (setq ver2 2)
    (setq CXLINEA (+ CX1 (* 10.0 MSC1)))
    (setq CXACIMUT (+ CX1 (* 43.0 MSC1)))
    (setq CXDISTANCIA (+ CX1 (* 65.0 MSC1)))
    ;**********************************************************************
    (REPEAT (length vertices-lista)
    (setq X (CAR (NTH cont vertices-lista))) ;coordenada X
    (setq Y (CADR (NTH cont vertices-lista))) ;coordenada Y
    (setq stx (+ stx X))
    (setq sty (+ sty Y))

    (if (> cont1 control)
    (setq cont1 0)
    )
    (setq X1 (CAR (NTH cont1 vertices-lista))) ;coordenada X
    (setq Y1 (CADR (NTH cont1 vertices-lista))) ;coordenada Y

    (setq PTO1 (list X Y))
    (setq PTO2 (list X1 Y1))
    (setq ang-rad (angle PTO1 PTO2))
    (setq ang-rad (- (/ pi 2.0) ang-rad))
    ;**********************************************************************
    (setq ang-dec (* (/ 180 pi) ang-rad))
    (if (< ang-dec 0)
    (setq ang-dec (+ 360 ang-dec))
    )
    ;**********************************************************************
    (setq deg (fix ang-dec))
    (setq deg2 (rtos deg 2 0))
    (if (= (strlen deg2) 1)
    (setq degstr (strcat "0" deg2 (chr 186)))
    (setq degstr (strcat deg2 (chr 186)))
    )

    (setq rem1 (- ang-dec deg))
    (setq min1 (* rem1 60))
    (setq min2 (fix min1))
    (setq min3 (rtos min2 2 0))
    (if (= (strlen min3) 1)
    (setq minstr (strcat "0" min3 (chr 39)))
    (setq minstr (strcat min3 (chr 39)))
    )

    (setq sec (- min1 min2))
    (setq sec2 (rtos (* 60 sec) 2 0))
    ;**********************************************************************
    ;-------------------------INICIA CONDICIÓN SI SEC2 = "60"
    (if (= sec2 "60")
    (progn
    (setq sec2 "00")
    (setq min22(+ min2 1))
    (setq min3 (rtos min22 2 0))
    (if (= (strlen min3) 1)
    (setq minstr (strcat "0" min3 (chr 39)))
    (setq minstr (strcat min3 (chr 39)))
    )
    )
    )
    ;-------------------------TERMINA CONDICIÓN SI SEC2 = "60"
    (if (= (strlen sec2) 1)
    (setq secstr (strcat "0" sec2 (chr 34)))
    (setq secstr (strcat sec2 (chr 34)))
    )
    (if (= min3 "60")
    (progn
    (setq minstr (strcat "00" (chr 39)))
    ;(setq min3 "00")
    (setq deg22(+ deg 1))
    (setq deg2 (rtos deg22 2 0))
    (if (= (strlen deg2) 1)
    (setq degstr (strcat "0" deg2 (chr 186)))
    (setq degstr (strcat deg2 (chr 186)))
    )
    )
    )
    ;----------------------

    (setq ang-final (strcat degstr minstr secstr))
    ;**********************************************************************
    (setq azimuth (strcat (vl-string-subst (chr 176) "d" (angtos (- (* pi 0.5) ang-rad) 1 3))))

    (setq dist (distance PTO1 PTO2))
    (setq CP (LIST CXLINEA CYT1))
    (setq CE (LIST CXACIMUT CYT1))
    (setq CN (LIST CXDISTANCIA CYT1))
    (if (> ver1 (+ control 1))
    (setq ver1 1)
    )

    (if (> ver2 (+ control 1))
    (setq ww 65)
    )

    (setq lineatx (strcat (chr w) " - " (chr ww)))

    (setq linea (strcat (rtos vert 2 0) " - " (rtos ver1 2 0)))

    (command "text" "j" "r" CN ht "90" (rtos dist 2 2))
    ; (command "text" "j" "r" CE ht "90" azimuth)
    ; (command "text" "j" "c" CP ht "90" linea)

    (command "text" "j" "c" CP ht "90" lineatx)

    ; (command "text" "j" "r" CE ht "90" (rtos ang-dec 2 4))
    (command "text" "j" "r" CE ht "90" ang-final)

    (setq cont (1+ cont))
    (setq cont1 (1+ cont1))
    (setq CYT1 (- CYT1 (* 5.0 MSC1)))
    (setq vert (+ vert 1))
    (setq ver1 (+ ver1 1))
    (setq ver2 (+ ver2 1))
    (setq CYAREA CYT1)

    (setq w (+ 1 w))
    (setq ww (+ 1 ww))
    )
    ;**********************************************************************
    (setq stx (/ stx nv)) (setq sty (/ sty nv))
    (setq PA (list stx sty))
    (command "text" "j" "c" PA ht "90" (strcat (rtos aa 2 2)"m2"))
    (setq PTO3 (polar PO 0 FSC4))
    (setq CX1 (NTH 0 PO))
    (setq CY1 (NTH 1 PO))

    (setq CY2 (- CY1 (* 5.0 MSC1)))
    (setq PTO4 (list CX1 CY2))

    (setq PTO5 (polar PTO4 0 FSC4))
    (setq CY2 (- CY2 (* 5.0 MSC1)))
    (setq PTO6 (list CX1 CY2))
    (setq PTO7 (polar PTO6 0 FSC4))
    (command "color" "5")
    (command "line" PO PTO3 "")
    (command "line" PTO4 PTO5 "")
    (command "line" PTO6 PTO7 "")
    (command "color" "bylayer")
    ;**********************************************************************
    (REPEAT (+ 1 control)
    (setq CY2 (- CY2 (* 5.0 MSC1)))
    (setq PTO6 (list CX1 CY2))
    (setq PTO7 (polar PTO6 0 FSC4))
    (command "line" PTO6 PTO7 "")
    )
    ;**********************************************************************
    (command "color" "5")
    (setq PTO8 (polar PTO4 0 FSC2))
    (setq PTO9 (polar PTO4 0 FSC3))
    (setq PTO10 (polar PTO6 0 FSC2))
    (setq PTO11 (polar PTO6 0 FSC3))
    (command "line" PO PTO6 "")
    (command "line" PTO3 PTO7 "")
    (command "line" PTO8 PTO10 "")
    (command "line" PTO9 PTO11 "")

    (setq CXT1 (+ CX1 (* 35.0 MSC1)))
    (setq CYT1 (- CY1 (* 3.5 MSC1)))
    (setq TITULO (LIST CXT1 CYT1))

    (setq CXT1 (+ CX1 (* 10.0 MSC1)))
    (setq CYT1 (- CY1 (* 8.5 MSC1)))
    (setq LINEA (LIST CXT1 CYT1))

    (setq CXT2 (+ CX1 (* 35.0 MSC1)))
    (setq CYT2 (- CY1 (* 8.5 MSC1)))
    (setq ACIMUT (LIST CXT2 CYT2))

    (setq CXT3 (+ CX1 (* 60.0 MSC1)))
    (setq CYT3 (- CY1 (* 8.5 MSC1)))
    (setq DISTANCIA (LIST CXT3 CYT3))

    (setq CA (LIST CXT2 CYAREA))
    (setq Superficie (strcat "Area: " (rtos aa 2 2) "m² Perimetro: " (rtos pp 2 2) "m"))
    ;**********************************************************************
    (command "color" "4")
    (command "TEXT" "j" "c" TITULO HT "90" "* DERROTERO *")
    (command "color" "3")
    (command "TEXT" "j" "c" LINEA HT "90" "LINEA")
    (command "TEXT" "j" "c" ACIMUT HT "90" "ACIMUT")
    (command "TEXT" "j" "c" DISTANCIA HT "90" "DIST.(m)")
    (command "TEXT" "J" "C" CA HT "90" Superficie)
    ;**********************************************************************
    (setvar "clayer" "0") ;capa cero
    (command "color" "bylayer")
    (setvar "osmode" 45)
    ;**********************************************************************
    ) ;Fin del Defun


    Once again, thank you for your time

  6. #6
    Login to Give a bone
    0

    Default Re: Polyline clockwise

    Tom, thanks for your help.
    I have a lisp routine that calculates a table of technical data: azimuth and distance. Calculate this data depending on the direction of the polyline, it can be clockwise or it can be counterclockwise.
    I want it to always be clockwise, for which I need to add to the main lisp another lisp that works as a function that converts the polylines in a counterclockwise sense to a clockwise direction.

    I attach the lisp I have
    Attached Files Attached Files

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Polyline clockwise

    To start I wrote some code to determine if a polyliine is clockwise or not.

    It can also be used to determine if a point is inside or outside a polyline.

    I thought I could do it shorter (I could probably tighten it up) but I thought I would post it as is.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2017 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ;  Abstract: This routine allows the user to select a polyline. It develops a list of verticies and checks
    ;  the inside and outside angles of each corner. The summation of the angles determines the direction.
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Function Header List
    ;___________________________________________________________________________________________________________|
    
    
    ;* C:PIC
    ;* Command line function to check if a polyline is clockwise or counter clockwise
    
    ;* C:PolylineIsClockwise
    ;* Command line function to check if a polyline is clockwise or counter clockwise
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    ;
    ;  Function List		Argument1	Argument2 	Arguement3
    
    
    ;* (AnglesDelta lstPoint1 lstPOint2 lstPoint3)
    ;* Function to determine the angle between three points
    
    ;* (MatrixTranspose lstMatrix)
    ;* Function to Transpose a matrix
    
    ;* (Point2D lstPoint)
    ;* Function to convert a 3d point to a 2d point
    
    ;* (PolylineVertexList objPolyline)
    ;* Function to get a list of verticies from a polyline
    
    ;* (SublistMoveToEnd lstOfSublists)
    ;* Function to move a sublist from the from of a list to the end
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command line function to check if a polyline is clockwise or counter clockwise
    ;___________________________________________________________________________________________________________|
    
    (defun C:PIC ()(C:PolylineIsClockwise))
    
    (defun C:PolylineIsClockwise (/ entSelection lstOfSublists lstPoints1 lstPoints2 lstPoints3 lstTranspose objSelection ssSelection)
     (if (and (setq ssSelection   (ssget ":S:E" (list (cons 0 "polyline,lwpolyline"))))
              (setq entSelection  (ssname ssSelection 0))
              (setq objSelection  (vlax-ename->vla-object entSelection))
              (setq lstPoints1    (PolylineVertexList objSelection))
              (setq lstPoints2    (SublistMoveToEnd lstPoints1))
              (setq lstPoints3    (SublistMoveToEnd lstPoints2))
              (setq lstOfSublists (mapcar 'AnglesDelta lstPoints1 lstPoints2 lstPoints3))
              (setq lstTranspose  (Matrixtranspose lstOfSublists))
             
         )
      (if (> (apply '+ (car lstTranspose))
             (apply '+ (cadr lstTranspose))
          )
       "Clockwise"
       "CounterClockwise"
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to determine the angle between three points
    ;___________________________________________________________________________________________________________|
    
    (defun AnglesDelta (lstPoint1 lstPOint2 lstPoint3 / sngDegrees  sngDelta)
     (if Debug (princ "\nAnglesDelta: "))
     (setq sngDelta   (- (angle lstPoint2 lstPoint3)(angle lstPoint1 lstPoint2)))
     (setq sngDegrees (* (/ sngDelta pi) 180.0))
     (while (> sngDegrees 360.0) (setq sngDegrees (- sngDegrees 360.0)))
     (while (< sngDegrees 0.0) (setq sngDegrees   (+ sngDegrees 360.0)))
     (list sngDegrees (- 360.0 sngDegrees))
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to Transpose a matrix
    ;___________________________________________________________________________________________________________|
    
    (defun MatrixTranspose (lstMatrix)
     (if Debug (princ "\nMatrixTranspose: "))
     (if (car lstMatrix)
      (cons (mapcar 'car lstMatrix)
            (MatrixTranspose (mapcar 'cdr lstMatrix))
      )
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to convert a 3d point to a 2d point
    ;___________________________________________________________________________________________________________|
    
    (defun Point2D (lstPoint)
     (if Debug (princ "\nPoint2d: "))
     (while (> (length lstPoint) 2)
      (setq lstPoint (reverse (cdr (reverse lstPoint))))
     )
     lstPoint
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to get a list of verticies from a polyline
    ;___________________________________________________________________________________________________________|
    
    (defun PolylineVertexList (objPolyline / intCount lstReturn)
     (if Debug (princ "\nPolylineVertexList: "))
     (repeat (setq intCount (fix (+ 0.001 (vlax-curve-getendparam objPolyline))))
      (setq lstReturn (cons (vlax-curve-getpointatparam objPolyline (float intCount)) lstReturn))
      (setq intCount (1- intCount))
     )
     lstReturn
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to move a sublist from the from of a list to the end
    ;___________________________________________________________________________________________________________|
    
    (defun SublistMoveToEnd (lstOfSublists)
     (if Debug (princ "\nSublistMoveToEnd: "))
     (reverse (cons (car lstOfSublists) (reverse (cdr lstOfSublists))))
    )
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    AutomateCAD

Similar Threads

  1. 2015: Structure label style clockwise
    By steenfredrik427250 in forum AutoCAD Civil 3D - General
    Replies: 0
    Last Post: 2015-12-22, 01:27 PM
  2. 2013: z value at intersection points in 3d polyline and polyline
    By jaychandran in forum AutoCAD Civil 3D - General
    Replies: 1
    Last Post: 2013-10-30, 05:20 PM
  3. Replies: 14
    Last Post: 2007-09-10, 05:01 PM
  4. Replies: 17
    Last Post: 2006-11-30, 02:15 AM
  5. Clockwise/Anti-clockwise Polyline
    By csgohjmj in forum AutoLISP
    Replies: 2
    Last Post: 2004-08-07, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •