Jump to content

Recommended Posts

Posted

Hi again.

This may also happen to others: sometimes I have two polylines and I need to get something like a common parallel to both. A sort of hybrid parallel from the original two.

Is it possible that this topic has been discussed in the history of this forum and there is a LISP to solve this problem?

 

Thanks in advance.

Posted (edited)

Posting a drawing would help to be more clear with what your asking for. but maybe this is what your looking for. PAV

Edited by mhupp
  • Thanks 1
Posted
1 hour ago, mhupp said:

Posting a drawing would help to be more clear with what your asking for. but maybe this is what your looking for. PAV

 

This?

Img1.thumb.png.07fd814eb89e5e7b30286584da757f3c.png

Posted (edited)

Perhaps the most appropriate description is to obtain the axis between 2 irregular polylines

Edited by PGia
Posted
52 minutes ago, pkenewell said:

Look into this post for ideas:

 

@pkenewell Thanks for help.

I downloaded the latest code from link and loaded it, but it doesn't seem to do anything.

I probably don't understand how it works.

Posted
1 hour ago, PGia said:

I tried it. But it only works sometimes. And if the polylines' first point coincides with the last, it doesn't work.

Is it possible that I'm doing something wrong?

The code does not work correctly with polylines that have a large number of segments.

Example1.dwg

Posted (edited)
1 hour ago, PGia said:

Thanks for help.

I downloaded the latest code from link and loaded it, but it doesn't seem to do anything.

I probably don't understand how it works.

 The "MC" command by roy437 works for me on your example drawing. You have to set the point resolution (prompt for "Specify Length for arc(ds)") to improve the results. I used 0.1 for pretty good results.

image.thumb.png.7acdec84578d497be076d0c039da43f0.png

Edited by pkenewell
Posted
54 minutes ago, pkenewell said:

 The "MC" command by roy437 works for me on your example drawing. You have to set the point resolution (prompt for "Specify Length for arc(ds)") to improve the results. I used 0.1 for pretty good results.

image.thumb.png.7acdec84578d497be076d0c039da43f0.png

 

@pkenewell Thank you very much.

I finally got it working.

In my case, I set the "length of arcs" to 1. And it worked. But I think the resulting axis isn't very geometrically rigorous. I've attached an example image:

Img1.thumb.png.ffd86ff3213d0926b6d8db658c1fb27f.png

-The polyline created by the command is shown in green.

-The correct geometry of the axis is shown in dashed red.

 

I think there should be a more geometrically rigorous solution in some older Lisp.

Is it possible?

Does anyone know of one?

Posted (edited)

Select both polylines

find the polyline that has the most vertex

Then process those vertex with vlax-curve-getClosestPointTo

store the mid point of vertex and closest point in a list

entmake new polyline with list points.

 

Seems to work well tho will need to test if you have open or closed polylines. defaults to closed tho i don't think its quite the mid / avg path

 

;;----------------------------------------------------------------------------;;
;; CLOSE POLY AVERAGE, Finds the mid point avg between close polylines donut shape
(defun c:CLOSEPOLYAVG (/ sel1 sel2 ent1 ent2 cnt1 cnt2 main other i ptv ptc mid pts)
  (defun c:CPA () (C:CLOSEPOLYAVG))  
  (defun midpt (p1 p2)
    (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2)
  )
  (setq sel1 (entsel "\nSelect First close Polyline: "))
  (setq sel2 (entsel "\nSelect Second closed Polyline: "))
  (if (and sel1 sel2)
    (progn
      (setq ent1 (vlax-ename->vla-object (car sel1))
            ent2 (vlax-ename->vla-object (car sel2))
            cnt1 (fix (vlax-curve-getEndParam ent1))
            cnt2 (fix (vlax-curve-getEndParam ent2))
	  )
      (if (> cnt1 cnt2)
        (setq main ent1 other ent2)
        (setq main ent2 other ent1)
      )
      (setq pts '())
      (setq i 0)
      (while (<= i (fix (vlax-curve-getEndParam main)))
        (setq ptv (vlax-curve-getPointAtParam main i))
        (setq ptc (vlax-curve-getClosestPointTo other ptv))
        (setq mid (midpt ptv ptc))
        (setq pts (append pts (list mid)))
        (setq i (1+ i))
      )
      (entmake
        (append
          (list
            '(0 . "LWPOLYLINE")
            '(100 . "AcDbEntity")
            '(100 . "AcDbPolyline")
            (cons 90 (length pts))
            '(70 . 1) ;; closed
          )
          (mapcar '(lambda (p) (cons 10 p)) pts)
        )
      )
      (princ "\nNew midpoint polyline created.")
    )
    (princ "\nSelection error.")
  )
  (princ)
)

 

image.thumb.png.09612861d4029bce7f63fc34ad46cd26.png

Edited by mhupp
  • Thanks 1
Posted (edited)
On 10/20/2025 at 10:35 PM, mhupp said:

Select both polylines

find the polyline that has the most vertex

Then process those vertex with vlax-curve-getClosestPointTo

store the mid point of vertex and closest point in a list

entmake new polyline with list points.

 

Seems to work well tho will need to test if you have open or closed polylines. defaults to closed tho i don't think its quite the mid / avg path

 

;;----------------------------------------------------------------------------;;
;; CLOSE POLY AVERAGE, Finds the mid point avg between close polylines donut shape
(defun c:CLOSEPOLYAVG (/ sel1 sel2 ent1 ent2 cnt1 cnt2 main other i ptv ptc mid pts)
  (defun c:CPA () (C:CLOSEPOLYAVG))  
  (defun midpt (p1 p2)
    (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2)
  )
  (setq sel1 (entsel "\nSelect First close Polyline: "))
  (setq sel2 (entsel "\nSelect Second closed Polyline: "))
  (if (and sel1 sel2)
    (progn
      (setq ent1 (vlax-ename->vla-object (car sel1))
            ent2 (vlax-ename->vla-object (car sel2))
            cnt1 (fix (vlax-curve-getEndParam ent1))
            cnt2 (fix (vlax-curve-getEndParam ent2))
	  )
      (if (> cnt1 cnt2)
        (setq main ent1 other ent2)
        (setq main ent2 other ent1)
      )
      (setq pts '())
      (setq i 0)
      (while (<= i (fix (vlax-curve-getEndParam main)))
        (setq ptv (vlax-curve-getPointAtParam main i))
        (setq ptc (vlax-curve-getClosestPointTo other ptv))
        (setq mid (midpt ptv ptc))
        (setq pts (append pts (list mid)))
        (setq i (1+ i))
      )
      (entmake
        (append
          (list
            '(0 . "LWPOLYLINE")
            '(100 . "AcDbEntity")
            '(100 . "AcDbPolyline")
            (cons 90 (length pts))
            '(70 . 1) ;; closed
          )
          (mapcar '(lambda (p) (cons 10 p)) pts)
        )
      )
      (princ "\nNew midpoint polyline created.")
    )
    (princ "\nSelection error.")
  )
  (princ)
)

 

image.thumb.png.09612861d4029bce7f63fc34ad46cd26.png

 

Thanks again for your code, @mhupp

It seems that the differences in the turning zones between the resulting geometry and the expected geometry persist.
I must say that the goal is to obtain an axis that remains equidistant from the reference polylines at all times.

I thought this problem would easily find a solution here.
Maybe I was wrong

Edited by PGia
Posted (edited)

like i said its not really the avg per say because its missing data points. should probably use the larger/longer poly to pull points from (or maybe both and avg it out). The blue line is suffering from not enough detail since its only calculating off the vertex. i can't test right now but see if the selecting order changes anything.

 

Also change the following and should get a better path. tho it will create a poly with 10x the vertex of selected one.

 

(setq i (+ i 0.1))

 

 

Edited by mhupp
Posted

Here's a simpe solution that doesn't use LISP.

Change the elevation of one of the polylines to 1.0 then use the loft command to create asurface.  Section the resulting surface with an XY plane at 0,0,0.5.

image.png.f260f5cbc11e3d38ddf0705a58437e0e.png

image.png.14ca000938db778dbbb2076a4bb16e3e.png

 

  • Like 1
  • Agree 3
Posted
2 hours ago, lrm said:

Here's a simpe solution that doesn't use LISP.

Change the elevation of one of the polylines to 1.0 then use the loft command to create asurface.  Section the resulting surface with an XY plane at 0,0,0.5.

image.png.f260f5cbc11e3d38ddf0705a58437e0e.png

image.png.14ca000938db778dbbb2076a4bb16e3e.png

 

 

Thanks, @lrm

It seems your method relies on there being pairs of points close together between both polylines.

But when several points accumulate on one of them and don't find a corresponding point on the other, the calculated axis deviates from the center, and the method loses consistency.

To keep these cases under control, I think it is best to manage them using a Lisp.

But maybe I'm wrong 😅

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