thebiglebowski Posted April 20, 2020 Posted April 20, 2020 (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 April 20, 2020 by thebiglebowski Quote
dlanorh Posted April 20, 2020 Posted April 20, 2020 (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 April 20, 2020 by dlanorh 1 Quote
Recommended Posts
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.