Sorting Rectangle Vector List

Discussion in 'AutoCAD' started by David Bethel, Jul 27, 2003.

  1. David Bethel

    David Bethel Guest

    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
     
    David Bethel, Jul 27, 2003
    #1
  2. David Bethel

    David Bethel Guest

    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
     
    David Bethel, Jul 27, 2003
    #2
  3. David Bethel

    Joe Burke Guest

    I think that RectPts function is broken.

    Joe Burke
     
    Joe Burke, Jul 28, 2003
    #3
  4. David Bethel

    Joe Burke Guest

    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))
    )
    )
     
    Joe Burke, Jul 28, 2003
    #4
  5. David Bethel

    David Bethel Guest

    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 Bethel, Jul 28, 2003
    #5
  6. David Bethel

    Joe Burke Guest

    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
     
    Joe Burke, Jul 28, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.