Jump to content

Looking for Ideas - Closest Pair of Vertices Between Two Seperate Polylines


Recommended Posts

Posted (edited)

I want to find the closest pair of vertices between any two LWPOLYINES.

 

The only way I can think of would be to compile multiple lists. Each list would contain the distance of 1 vertex on Polyline #1 to every vertex on Polyline #2. This would then have to be repeated for every vertex on Polyline #1. Every list compiled would be sorted by descending values. A Final list would be compiled by pulling the first values from all the other lists. This will give you the closest pair of vertices between the two polylines.

 

The problem is this could require tens of thousands of permutations on more complex polylines. Is there a simpler way to do this?

 

Edited by thebiglebowski
Posted (edited)

Why so complicated?

 

Try this

 

(defun c:test ( / e1 e2 v1lst v2lst min_dist av bv)
  (setq e1 (car (entsel "\nSelect First Polyline : "))
        e2 (car (entsel "\nSelect First Polyline : "))
        v1lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e1)))
        v2lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e2)))
        min_dist 1.0e99
        av nil
        bv nil
  )
  (foreach y v1lst (mapcar '(lambda (x) (if (< (distance y x) min_dist) (setq min_dist (distance y x) av y bv x))) v2lst))
  (entmakex (list '(0 . "LINE") (cons 10 av) (cons 11 bv) '(62 . 1)))
  (princ (strcat "\nMin Inter Vertex Distance Poly 1 to Poly 2 : " (rtos min_dist 2 3)))
)

 

It will draw a red line between two vertices and print the distance on the command line

Edited by dlanorh
  • Like 1

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