Author Topic: Perimeter (length) of the offset without doing the offset  (Read 1457 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Perimeter (length) of the offset without doing the offset
« on: August 14, 2021, 03:39:12 AM »
Is possible to calculate the length of the offset of a polyline without doing the offset?
The perimeter is internal if the polyline is closed and external if open. Currently I do the internal and external offset and take the one with a greater or lesser length depending on whether the polyline is open or closed, then I delete the offset.

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: Perimeter (length) of the offset without doing the offset
« Reply #1 on: August 14, 2021, 07:02:50 AM »
Currently I do the internal and external offset and take the one with a greater or lesser length depending on whether the polyline is open or closed
if the polyline is open one can not decide which offset is internal or external by just measuring the length


VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: Perimeter (length) of the offset without doing the offset
« Reply #3 on: August 14, 2021, 09:24:24 AM »
It is true  :yes: :knuppel2: :)
so there is no solution
we can only calculate the length of the line offset to the left or to the right side

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Perimeter (length) of the offset without doing the offset
« Reply #4 on: August 14, 2021, 09:47:20 AM »
i am trying to use an idea of RJP where the resulting areas are compared (i think for my polyline types this is enough):
Code: [Select]
(defun c:foo (/ _off a b c d o o1 o2 p s x)
  ;; RJP - 07.17.2018
  ;; Offsets a pline twice and joins them
  ;; Does not work with polylines that have arc segments
  (defun _off (o d / r)
    (cond ((= 'list (type (setq r (vl-catch-all-apply 'vlax-invoke (list o 'offset d))))) (car r)))
  )
  (cond ((and (setq s (ssget ":L" '((0 . "lwpolyline") (-4 . ">") (90 . 2))))
              (not (initget "Outside Inside"))
              (setq p (cond ((getkword "\nOffset [Outside/Inside] <Outside>: "))
                            ("Outside")
                      )
              )
         )
         (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
           (setq c nil)
           (setq o (vlax-ename->vla-object e))
           (setq a (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget e))))
           (setq
             o (vl-remove
                 'nil
                 (mapcar
                   '(lambda (x) (cond ((setq d (_off o (x 45))) (list d x (vlax-curve-getarea d)))))
                   (list + -)
                 )
               )
           )
           (cond ((= 2 (length o))
                  (setq o (vl-sort o '(lambda (r j) (< (caddr r) (caddr j)))))
                  (cond ((= p "Outside") (setq o (reverse o))))
                  (vla-delete (car (cadr o)))
                  (setq o1 (caar o))
                  (setq b (vlax-get o1 'coordinates))
                  (vlax-put o1 'coordinates (append (car a) b (last a)))
                  (setq o2 (car (vlax-invoke o1 'offset ((cadar o) 10))))
                  (setq a (vlax-get o1 'coordinates))
                  (setq b (vlax-get o2 'coordinates))
                  (while b (setq c (cons (list (car b) (cadr b)) c)) (setq b (cddr b)))
                  (vlax-put o1 'coordinates (append a (apply 'append c)))
                  (vla-put-closed o1 :vlax-true)
                  (vla-put-color o1 30)
                  (vla-delete o2)
                 )
           )
         )
        )
  )
  (princ)
)

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Perimeter (length) of the offset without doing the offset
« Reply #6 on: August 14, 2021, 11:11:36 AM »
Pseudo code:
Code: [Select]
(defun ALE_Draw_Offset (VlaObj OffDst / RetVal)
  (cond ( (= 'list (type (setq RetVal (vl-catch-all-apply 'vlax-invoke (list VlaObj 'offset OffDst))))) (car RetVal) ) )
)
(defun ALE_Pline_TwiceOffset (VlaObj OffDst)
  (vl-remove 'nil
    (mapcar
     '(lambda (LmbDat)
        (cond ( (setq CoDLst (FunOff VlaObj (LmbDat OffDst))) (list CoDLst LmbDat (vlax-curve-getarea CoDLst)) ))
      )
      (list + -)
    )
  )
)
(defun ALE_Pline_OffsetInOut (InfLst Out_In) ; Out_In 0 = Out - 1 = In
  (if (zerop Out_In)
    (setq InfLst (reverse (vl-sort InfLst '(lambda (r j) (< (caddr r) (caddr j))))))
    (setq InfLst (vl-sort InfLst '(lambda (r j) (< (caddr r) (caddr j)))))
  )
  (vla-delete (car (cadr InfLst)))
  (caar InfLst)
)
(setq InfLst (ALE_Pline_TwiceOffset vvv 30))
(vla-get-Length (ALE_Pline_OffsetInOut InfLst 0))