Code Red > AutoLISP (Vanilla / Visual)

Sort a list of points

(1/2) > >>

Marc'Antonio Alessi:
Problem: find the "pair of greater distances" and order the list of points so that it starts from the vertex between the two segments keeping the same ordering (in this case clockwise).
Edit: new condition > the two distances chosen must not be less than "x" (example 40)
For simplicity I have made an example with orthogonal polyline but it may not be...

--- Code: ---Examples of list:
((  0.0  0.0 0.0) (  0.0 30.0 0.0) ( 15.0 30.0 0.0) ( 15.0 80.0 0.0) ( 35.0 80.0 0.0) ( 35.0 30.0 0.0) (105.0 30.0 0.0) (105.0  0.0 0.0))
((105.0  0.0 0.0) (  0.0  0.0 0.0) (  0.0 30.0 0.0) ( 15.0 30.0 0.0) ( 15.0 80.0 0.0) ( 35.0 80.0 0.0) ( 35.0 30.0 0.0) (105.0 30.0 0.0))
((105.0 30.0 0.0) (105.0  0.0 0.0) (  0.0  0.0 0.0) (  0.0 30.0 0.0) ( 15.0 30.0 0.0) ( 15.0 80.0 0.0) ( 35.0 80.0 0.0) ( 35.0 30.0 0.0))
(( 35.0 30.0 0.0) (105.0 30.0 0.0) (105.0  0.0 0.0) (  0.0  0.0 0.0) (  0.0 30.0 0.0) ( 15.0 30.0 0.0) ( 15.0 80.0 0.0) ( 35.0 80.0 0.0)) ;<<<<
(( 35.0 80.0 0.0) ( 35.0 30.0 0.0) (105.0 30.0 0.0) (105.0  0.0 0.0) (  0.0  0.0 0.0) (  0.0 30.0 0.0) ( 15.0 30.0 0.0) ( 15.0 80.0 0.0))
(( 15.0 80.0 0.0) ( 35.0 80.0 0.0) ( 35.0 30.0 0.0) (105.0 30.0 0.0) (105.0  0.0 0.0) (  0.0  0.0 0.0) (  0.0 30.0 0.0) ( 15.0 30.0 0.0))
(( 15.0 30.0 0.0) ( 15.0 80.0 0.0) ( 35.0 80.0 0.0) ( 35.0 30.0 0.0) (105.0 30.0 0.0) (105.0  0.0 0.0) (  0.0  0.0 0.0) (  0.0 30.0 0.0))
((  0.0 30.0 0.0) ( 15.0 30.0 0.0) ( 15.0 80.0 0.0) ( 35.0 80.0 0.0) ( 35.0 30.0 0.0) (105.0 30.0 0.0) (105.0  0.0 0.0) (  0.0  0.0 0.0))

Each list must give this result:
(( 35.0 30.0 0.0) (105.0 30.0 0.0) (105.0  0.0 0.0) (  0.0  0.0 0.0) (  0.0 30.0 0.0) ( 15.0 30.0 0.0) ( 15.0 80.0 0.0) ( 35.0 80.0 0.0))

--- End code ---

ribarm:
Marc'
(105+30) > (70+50)

According to your picture, you proposed wrong vertex for start (it should be IMHO LR - lower right point)...

ribarm:
When I think twice, it could also be LL (lower left point) or 0,0,0 in your CS...

Marc'Antonio Alessi:

--- Quote from: ribarm on June 17, 2021, 11:08:27 AM ---Marc'
(105+30) > (70+50)

According to your picture, you proposed wrong vertex for start (it should be IMHO LR - lower right point)...

--- End quote ---
Thanks Marko, for  "pair of greater distances" I don't mean the sum but the highest pair of values (I don't know how to explain better) but maybe this is not possible ...

I think we need a further condition:
> that the two distances chosen are not less than x (example 40)

ribarm:
I won!!!


--- Code: ---(defun foo ( l / dl pairs pair pos p )
  (setq dl (mapcar '(lambda ( a b ) (distance a b)) l (append (cdr l) (list (car l)))))
  (setq pairs (mapcar '(lambda ( a b ) (list a b)) dl (append (cdr dl) (list (car dl)))))
  (setq pair (car (vl-sort (vl-remove-if '(lambda ( x ) (vl-some '(lambda ( y ) (< y 40.0)) x)) pairs) '(lambda ( a b ) (> (+ (car a) (cadr a)) (+ (car b) (cadr b)))))))
  (setq pos (vl-position pair pairs))
  (setq p (nth (1+ pos) (append l l)))
  (append (member p l) (reverse (cdr (member p (reverse l)))))
)

(princ (foo '((0.0 0.0 0.0) (0.0 30.0 0.0) (15.0 30.0 0.0) (15.0 80.0 0.0) (35.0 80.0 0.0) (35.0 30.0 0.0) (105.0 30.0 0.0) (105.0 0.0 0.0))))
(princ (foo '((105.0 0.0 0.0) (0.0 0.0 0.0) (0.0 30.0 0.0) (15.0 30.0 0.0) (15.0 80.0 0.0) (35.0 80.0 0.0) (35.0 30.0 0.0) (105.0 30.0 0.0))))
(princ (foo '((105.0 30.0 0.0) (105.0 0.0 0.0) (0.0 0.0 0.0) (0.0 30.0 0.0) (15.0 30.0 0.0) (15.0 80.0 0.0) (35.0 80.0 0.0) (35.0 30.0 0.0))))
(princ (foo '((35.0 30.0 0.0) (105.0 30.0 0.0) (105.0 0.0 0.0) (0.0 0.0 0.0) (0.0 30.0 0.0) (15.0 30.0 0.0) (15.0 80.0 0.0) (35.0 80.0 0.0))))
(princ (foo '((35.0 80.0 0.0) (35.0 30.0 0.0) (105.0 30.0 0.0) (105.0 0.0 0.0) (0.0 0.0 0.0) (0.0 30.0 0.0) (15.0 30.0 0.0) (15.0 80.0 0.0))))
(princ (foo '((15.0 80.0 0.0) (35.0 80.0 0.0) (35.0 30.0 0.0) (105.0 30.0 0.0) (105.0 0.0 0.0) (0.0 0.0 0.0) (0.0 30.0 0.0) (15.0 30.0 0.0))))
(princ (foo '((15.0 30.0 0.0) (15.0 80.0 0.0) (35.0 80.0 0.0) (35.0 30.0 0.0) (105.0 30.0 0.0) (105.0 0.0 0.0) (0.0 0.0 0.0) (0.0 30.0 0.0))))
(princ (foo '((0.0 30.0 0.0) (15.0 30.0 0.0) (15.0 80.0 0.0) (35.0 80.0 0.0) (35.0 30.0 0.0) (105.0 30.0 0.0) (105.0 0.0 0.0) (0.0 0.0 0.0))))

--- End code ---

 :lol:

Navigation

[0] Message Index

[#] Next page

Go to full version