Sorting Rectangle Vector List

David Bethel

Usenet Archive
Joined
Nov 22, 2001
Messages
135
Reaction score
0
Greetings,

In plain AutoLISP

;;;Here are the point lists of (4) coplaner lines that form a 4 sided polygon ( never a bowtie - always an open face ).

(setq iv '(((1 1 0) (1 2 0))
((2 1 0) (2 2 0))
((1 2 0) (2 2 0))
((1 1 0) (2 1 0))))

;;;I'm looking to sort the list so that the common points are in order

;;;The resulting list would be consist of vectors like this:

(setq fl (list (nth 0 iv)
(nth 2 iv)
(reverse (nth 1 iv))
(reverse (nth 3 iv))))

'(((1 1 0) (1 2 0))
((1 2 0) (2 2 0))
((2 2 0) (2 1 0))
((2 1 0) (1 1 0))))

;;;This would extract the output points - CCW /CW direction is irelevant (foreach v fl (setq output (cons (car v) output)))

'((1 1 0) (1 2 0) (2 2 0) (2 1 0))

Any thoughts???? -David
 
I'll take a look see.

So far I've came up with

(setq iv '(((1 1 0) (1 2 0))
((2 1 0) (2 2 0))
((1 2 0) (2 2 0))
((1 1 0) (2 1 0))))

(setq output (list (car (car iv))
(cadr (car iv)))
iv (cdr iv))

(repeat (1- (length iv))
(foreach v iv
(cond ((and (equal (car v) (last output) 1e-14)
(not (member (cadr v) output)))
(setq output (append output (list (cadr v)))))
((and (equal (cadr v) (last output) 1e-14)
(not (member (car v) output)))
(setq output (append output (list (car v))))))))

(prin1 output)

-David
 
This seems to work right, but still feels like overkill.

Joe

(defun RectPts (l / lst nlst llur ullr)
(setq lst
(append
(mapcar 'car l)
(mapcar 'cadr l)
)
)
(foreach x lst
(if (not (member x nlst))
(setq nlst (cons x nlst))
)
)
(setq llur (extents nlst))
(foreach x nlst
(if (not (member x llur))
(setq ullr (cons x ullr))
)
)
(list (car llur) (car ullr) (cadr llur) (cadr ullr))
)

;by Tony Tanzillo - returns LL and UR corners of point list (defun extents (plist) (list (apply 'mapcar (cons 'min plist)) (apply 'mapcar (cons 'max plist)) )
)
 
Thanks Joe,

I'll look into all of 'em. I don't know if the /= will work, but (not (equal with fuzz cetainly will. -David
 
David,

Don't bother with the first two.

I considered this > (not (equal with fuzz certainly will. What I'd usually do. But thought I might be able to get away without it in this case. Anyway agreed, that's the safe method.

Joe
 

Latest threads

Back
Top