Jump to content

OFFSET (REVERSE) CENTERLINE(MIDDLE) MULTI-AREAS (POLYGONS)


leo321

Recommended Posts

HI, MASTERS

 

I LOOKING FOR HELP CAUSE GOT A DUTY OS 11,000 POLYGONS(NO ARC, JUST CLOSED POLYGONS ) LIKE THAT, (IMAGE) 

COULD BE ONE SINGLE LINE OR ONE  LINE FOR EACH AREA, SHOW IMAGE ALONG WAY THERE IS SOME ADJACENT AREAS PARALELLAS, ONE CONTINUE LINE WILL BE DIFFICULT TO COMPLETE IT I THINK.

 

 

image.thumb.png.68849af3933ef27a680314c920a9bba6.png 

Drawing2234.dwg

Link to comment
Share on other sites

This looks like a proposed road centerline, from experience you may not get an answer, you may get some helpers but not a complete solution. There is just to many variables. From past experience would pick a side and offset all the segments a fixed amount then play with fitting minimum radius and so on. 

 

There may be somewhere a curve fit program between 2 plines, with say min radius.

Link to comment
Share on other sites

Thank you, for the answer Bigal,
I opened the topic as a trial I knew it was a complex function as I had seen some previous posts that others had tried something similar I just came to confirm.

 

I saw that Argis has a similar function "poligon to centerline" I tried it but because it was too big it ended up giving an error.


In GM (Global) there is an "Area to Skeleton" that doesn't work well either, in addition to leaving the entire line broken, it also creates arms.

 

This is the best and only solution,
I'll put everything together in a single poly, then divide it into 2 and perform the offset.

 

obs: the hope was to have a tool(lisp) that is not even possible in GIS this would be something rare and unique

Edited by leo321
Link to comment
Share on other sites

hi @leo321

try code from  @Lee Mac

 

(defun c:cPoly (/ ent1 ent2 i j mPt len pt p1 ptlst grlst grlin)
(vl-load-com)

(if (and (setq ent1 (car (entsel "\nSelect First Polyline: ")))
(wcmatch (cdr (assoc 0 (entget ent1))) "*POLYLINE"))
(if (and (setq ent2 (car (entsel "\nSelect Second Polyline: ")))
(wcmatch (cdr (assoc 0 (entget ent2))) "*POLYLINE"))
(progn
(setq i -1 len 1 grlin '( ))
(while (and (grread 't)
(setq pt (vlax-curve-getPointatDist ent1 (* (setq i (1+ i)) len))))
(redraw)
(setq p1 (vlax-curve-getClosestPointto ent2 pt t)
ptlst (cons
(setq mPt
(polar pt (angle pt p1) (/ (distance pt p1) 2.))) ptlst) j -1 grlst nil)
(repeat 500
(setq grlst
(cons
(polar mPt (* (setq j (1+ j)) (/ pi 250.)) (distance mPt p1)) grlst)))
(setq grlin (append grlin (list (if grlin (last grlin) mPt) mPt)))
(grvecs (append '(3) grlst (cdr grlst) (list (car grlst))))
(grvecs (append '(1) grlin)))
(redraw)
(setq ptlst (apply 'append
(mapcar
(function
(lambda (x)
(list (car x) (cadr x)))) ptlst)))
(vla-AddLightWeightPolyline
(vla-get-ModelSpace
(vla-get-ActiveDocument
(vlax-get-acad-object)))
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray
vlax-VBDouble (cons 0 (1- (length ptlst)))) ptlst))))))

(princ))

Link to comment
Share on other sites

Hi,

If you cut your polylines so as to keep only the long edges (thus obtaining 2 polylines), you can try this.
You will get 2 polylines between the 2 polylines initially selected.
Keep the one that suits you best...
It's far from perfect, but can simplify your work.

(vl-load-com)
(defun add_vtx (obj add_pt ent_name / bulg)
  (vla-addVertex
    obj
    (1+ (fix add_pt))
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray vlax-vbdouble (cons 0 1))
          (list
            (car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
            (cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
          )
      )
    )
  )
  (setq bulg (vla-GetBulge obj (fix add_pt)))
  (vla-SetBulge obj
    (fix add_pt)
    (/
      (sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
      (cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
    )
  )
  (vla-SetBulge obj
    (1+ (fix add_pt))
    (/
      (sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
      (cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
    )
  )
  (vla-update obj)
)
(defun c:vertex_median ( / fst_ob snd_obj vrt_pt pt lst_pt fst_dxf snd_dxf lst1 lst2 lstx ptx)
  (princ "\nSelect the first polyline: ")
  (while (not (setq fst_obj (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
  (princ "\nSelect the second polyline: ")
  (while (not (setq snd_obj (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
  (setq
    fst_obj (ssname fst_obj 0)
    snd_obj (ssname snd_obj 0)
    vrt_pt (vlax-variant-value (vla-IntersectWith (vlax-ename->vla-object fst_obj) (vlax-ename->vla-object snd_obj) 0))
  )
  (if (>= (vlax-safearray-get-u-bound vrt_pt 1) 0)
    (progn
      (setq pt (vlax-safearray->list vrt_pt))
      (if pt
        (if (> (length pt) 3)
          (repeat (/ (length pt) 3)
            (setq lst_pt (cons (list (car pt) (cadr pt) (caddr pt)) lst_pt) pt (cdddr pt))
          )
          (setq lst_pt (cons pt lst_pt))
        )
      )
    )
  )
  (setq
    fst_dxf (entget fst_obj)
    snd_dxf (entget snd_obj)
    lst1 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) fst_dxf))
    lst2 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) snd_dxf))
    lstx nil
  )
  (if (and lst_pt (listp lst_pt))
    (progn
      (setq obj (vlax-ename->vla-object fst_obj))
      (foreach el lst_pt
        (if (not (member T (mapcar '(lambda (x) (equal (list (car el) (cadr el)) x 1E-8)) lst1)))
          (add_vtx obj (vlax-curve-getparamatpoint obj (vlax-curve-getClosestPointTo obj el)) fst_obj)
        )
      )
      (setq obj (vlax-ename->vla-object snd_obj))
      (foreach el lst_pt
        (if (not (member T (mapcar '(lambda (x) (equal (list (car el) (cadr el)) x 1E-8)) lst2)))
          (add_vtx obj (vlax-curve-getparamatpoint obj (vlax-curve-getClosestPointTo obj el)) snd_obj)
        )
      )
    )
  )
  (setq
    fst_dxf (entget fst_obj)
    snd_dxf (entget snd_obj)
    lst1 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) fst_dxf))
    lst2 (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) snd_dxf))
    lstx nil
  )
  (foreach n lst1
    (setq
      pt (nth (vl-position (apply 'min (setq lst_d (mapcar '(lambda (x) (distance n x)) lst2))) lst_d) lst2)
      ptx (list (* 0.5 (+ (car n) (car pt))) (* 0.5 (+ (cadr n) (cadr pt))))
      lstx (cons ptx lstx)
    )
  )
  (entmake
    (append
      (list
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (assoc 67 fst_dxf)
        (assoc 410 fst_dxf)
        (assoc 8 fst_dxf)
        (cons 62 1)
        (if (assoc 6 fst_dxf) (assoc 6 fst_dxf) (cons 6 "BYLAYER"))
        (if (assoc 370 fst_dxf) (assoc 370 fst_dxf) (cons 370 -1))
        (cons 100 "AcDbPolyline")
        (cons 90 (length lstx))
        (assoc 70 fst_dxf)
        (if (assoc 38 fst_dxf) (assoc 38 fst_dxf) (cons 38 0.0))
        (if (assoc 39 fst_dxf) (assoc 39 fst_dxf) (cons 39 0.0))
      )
      (apply 'append
        (mapcar
          '(lambda (x10)
            (list
              (cons 10 x10)
              '(40 . 0.0)
              '(41 . 0.0)
              '(42 . 0.0)
              '(91 . 0)
            )
          )
          lstx
        )
      )
      (list (assoc 210 fst_dxf))
    )
  )
  (setq fst_obj (entlast) lstx nil)
  (foreach n lst2
    (setq
      pt (nth (vl-position (apply 'min (setq lst_d (mapcar '(lambda (x) (distance n x)) lst1))) lst_d) lst1)
      ptx (list (* 0.5 (+ (car n) (car pt))) (* 0.5 (+ (cadr n) (cadr pt))))
      lstx (cons ptx lstx)
    )
  )
  (entmake
    (append
      (list
        (cons 0 "LWPOLYLINE")
        (cons 100 "AcDbEntity")
        (assoc 67 snd_dxf)
        (assoc 410 snd_dxf)
        (assoc 8 snd_dxf)
        (cons 62 1)
        (if (assoc 6 snd_dxf) (assoc 6 snd_dxf) (cons 6 "BYLAYER"))
        (if (assoc 370 snd_dxf) (assoc 370 snd_dxf) (cons 370 -1))
        (cons 100 "AcDbPolyline")
        (cons 90 (length lstx))
        (assoc 70 snd_dxf)
        (if (assoc 38 snd_dxf) (assoc 38 snd_dxf) (cons 38 0.0))
        (if (assoc 39 snd_dxf) (assoc 39 snd_dxf) (cons 39 0.0))
      )
      (apply 'append
        (mapcar
          '(lambda (x10)
            (list
              (cons 10 x10)
              '(40 . 0.0)
              '(41 . 0.0)
              '(42 . 0.0)
              '(91 . 0)
            )
          )
          lstx
        )
      )
      (list (assoc 210 snd_dxf))
    )
  )
  (setq snd_obj (entlast))
  (sssetfirst nil (ssadd snd_obj (ssadd fst_obj (ssadd))))
  (prin1)
)

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...