Shortest path

Shortest path

dani-perez
Advocate Advocate
1,534 Views
8 Replies
Message 1 of 9

Shortest path

dani-perez
Advocate
Advocate

Hello all,

 

I expect be able to explain my issue. I have a random field and I have to draw the shortest path, going over the full area (closed pline). I specify an offset distance between lines, and the final distances to going over some more than the area (in all sides). I guess direction and angle of the path (must be a pline) will depend of each field.

 

I am attaching a drawing as sample.

 

Regards.

0 Likes
Accepted solutions (2)
1,535 Views
8 Replies
Replies (8)
Message 2 of 9

Sea-Haven
Mentor
Mentor

For me a guess more horizontal, then trim sum line lengths use a +/- degrees say 5 and redo.

0 Likes
Message 3 of 9

dlanorh
Advisor
Advisor
Can you post a drawing saved in AutoCAD 2010 format.

I am not one of the robots you're looking for

0 Likes
Message 4 of 9

dani-perez
Advocate
Advocate

Hello sea.haven,

 

Thanks for replying. 

 

Yes, I redesign the paths many times in order to find the shortest way. If a routine can help me to save time, I will be very grateful

0 Likes
Message 5 of 9

dani-perez
Advocate
Advocate

Hello dlanorh,

 

Here you have,

 

Regards

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@dani-perez wrote:

.... I have a random field and I have to draw the shortest path, going over the full area (closed pline). .....


 

If by that you mean that the red path in your sample drawing should be running in the direction that results in its being the shortest total length possible, then I think the main direction of its "passes" would need to be parallel to the longer direction of the "field" shape.  All the stepping-over ends of the back and forth are "wasted" length, so you want as few of them as possible, which is why the main length direction of the path should be the same as the main length direction of the field.

 

To find what that main length direction is, you can use SmallestRectangle.lsp, with its SR command, available >here<.  Applied to your sample field shape, it gives this result [yellow]:

SR.PNG

Coincidentally, that happens to be exactly an orthogonal rectangle, but the routine works in whole-1-degree increments, so it could be that being rotated a quarter of a degree or something could be slightly more precisely the smallest rectangle, though that difference wouldn't make much difference to a path's overall length.

 

Does that look like a good starting point?  It obviously needs further development to get to what you want, but I think it will find the most length-efficient direction for the path to run its long segments.

Kent Cooper, AIA
0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
.... it could be that being rotated a quarter of a degree or something could be slightly more precisely the smallest rectangle. ....

 

[That turns out to be true.  When I changed the rotation increment to 1/4 degree instead of 1, the smallest rectangle was rotated 1/2 degree CCW from that yellow one.  When I changed it to 0.1 degree, the smallest one was rotated 0.4 degrees.  It could be tightened as far down as you need to go, with even smaller increments.]

Kent Cooper, AIA
0 Likes
Message 8 of 9

marko_ribar
Advisor
Advisor
Accepted solution

Study my reply from this topic :

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-polyline-shape/m-p/6845942/...

 

It is possible to find absolutely precise minimal enclosing rectangle of polygonal LWPOLYLINE, and that is OP's case posted in his DWG...

BTW. Change LM:ConvexHull sub function with this mod. :

  ;; Convex Hull  -  Lee Mac
  ;; Implements the Graham Scan Algorithm to return the Convex Hull of a list of points.
   
  (defun LM:ConvexHull ( lst / ch p0 )
      (cond
          (   (< (length lst) 4) lst)
          (   (setq p0 (car lst))
              (foreach p1 (cdr lst)
                  (if (or (< (cadr p1) (cadr p0))
                          (and (= (cadr p1) (cadr p0)) (< (car p1) (car p0)))
                      )
                      (setq p0 p1)
                  )
              )
              (setq lst (vl-remove p0 lst))
              (setq lst (append (list p0) lst))
              (setq lst
                  (vl-sort lst
                      (function
                          (lambda ( a b / c d )
                              (if (or (equal (setq c (angle p0 a)) (setq d (angle p0 b)) 1e-8) (and (or (equal c 0.0 1e-8) (equal c (* 2 pi) 1e-8)) (or (equal d 0.0 1e-8) (equal d (* 2 pi) 1e-8))))
                                  (< (distance (list (car p0) (cadr p0)) a) (distance (list (car p0) (cadr p0)) b))
                                  (< c d)
                              )
                          )
                      )
                  )
              )
              (setq ch (list (cadr lst) (car lst)))
              (foreach pt (cddr lst)
                  (setq ch (cons pt ch))
                  (while (and (caddr ch) (LM:Clockwise-p (caddr ch) (cadr ch) pt))
                      (setq ch (cons pt (cddr ch)))
                  )
              )
              (reverse ch)
          )
      )
  )
   
  ;; Clockwise-p  -  Lee Mac
  ;; Returns T if p1,p2,p3 are clockwise oriented or collinear
                   
  (defun LM:Clockwise-p ( p1 p2 p3 )
      (<  (-  (* (- (car  p2) (car  p1)) (- (cadr p3) (cadr p1)))
              (* (- (cadr p2) (cadr p1)) (- (car  p3) (car  p1)))
          )
          1e-8
      )
  )

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 9 of 9

dani-perez
Advocate
Advocate

Hello 

 

 

0 Likes