Shortest path

Shortest path

adaptacad
Advocate Advocate
769 Views
2 Replies
Message 1 of 3

Shortest path

adaptacad
Advocate
Advocate

Hello again everyone.
I'm trying to create a function that gets the shortest path between two points.
The objective is to select a set of points, determine the beginning and end, store all points in a variable and draw a polyline along the shortest path, obeying the rule that the distance between one point and another does not exceed 50 units. If you happen to overtake, just mark the points you have exceeded.
Leaving an example .dwg for ease of understanding.

I thank you for your availability.

adaptacad_0-1625406857429.png

 

;;reference 
;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/connect-selected-blocks-with-the-smallest-polyline-length/td-p/8419663

(defun closer (a b c)
  (< (distance a b)(distance a c))
)
(defun c:shortestway ( )
  ;;start point
  (setq start_point '(254.1110 1.6016 0.0000)) 
  ;;End point
  (setq end_point '(391.3819 138.1919 0.0000))
  ;;shortest distance
  (setq shortest_distance (distance start_point end_point))  
  ;;maximum span length
  (setq maximum_length 50.0)
  ;;select
  (setq select (ssget))
  ;;build a list with the points
  (repeat (setq i (sslength select))
    (setq lst (cons (cdr (assoc 10 (entget (ssname select (setq i (1- i)))))) lst))
  )
  (setq rte (list start_point))
  ;;loop
  (while lst 
    (setq start_point (car (vl-sort lst '(lambda (a b) (closer pni a b)))))
    (setq lst (vl-remove start_point lst))
    (setq rte (cons start_point rte))
  )
  ;;draw the pline
  (vl-cmdf "_.pline")
  (mapcar 'vl-cmdf (reverse rte))
  (vl-cmdf "")
)

;(c:shortestway)

 

 

 

0 Likes
770 Views
2 Replies
Replies (2)
Message 2 of 3

JamesMaeding
Advisor
Advisor

You mean "connect the dots with shortest lines possible < 50 ft"?

That is about what a delunay triangulation does.

What is your question though? the algorithm, or how to do it in lisp?

You need to explain better.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 3 of 3

ronjonp
Mentor
Mentor

You have to triangulate the points ( for edges ) then use this algorithm. Here is a lisp version of it.

0 Likes