sort point list..

Discussion in 'AutoCAD' started by cwitt, Feb 3, 2005.

  1. cwitt

    cwitt Guest

    I posted a few months ago regarding this problem, and was provided with
    a few ideas.. unfortunatly they don't seem to be doing what i need..

    a quick history:
    I am gathering text into a selection set, then extracting insertion
    points into a list (see figure "a") I need the lists sorted in such a
    way that it would always return a result like figure "b" (it may help
    you to understand if you take the points and plot them like a graph).


    Figure "a" (starting list):
    ((1,4)(1,3)(1,0)(2,2)(3,3)(3,1))

    Figure "b" (target list):
    ((1,4)(1,3)(3,3)(2,2)(3,1)(1,0))



    if the graph idea doesn't do it for you then try this:

    assign each point a word..
    1,4 this
    1,3 is
    1,0 want
    2,2 result
    3,3 the
    3,1 I

    once the points are sorted to match figure "b" it would read "This is
    the result I want".

    I hope someone can help me with this..

    Thanks.
     
    cwitt, Feb 3, 2005
    #1
  2. cwitt

    Doug Broad Guest

    Use vl-sort or vl-sort-i. Post the points in correct lisp format and I'll post a
    solution.
     
    Doug Broad, Feb 3, 2005
    #2
  3. cwitt

    cwitt Guest

    ((1,4)(1,3)(1,0)(2,2)(3,3)(3,1))

    that is correct lisp format.. or are you refering to the lack of a z cord?

    ((1,4,0)(1,3,0)(1,0,0)(2,2,0)(3,3,0)(3,1,0))
     
    cwitt, Feb 3, 2005
    #3
  4. cwitt

    Doug Broad Guest

    No it isn't.
    No

    If you can't express the points correctly, then any help I
    offer won't work.

    Try (getpoint) and see what it returns. Look closely.
     
    Doug Broad, Feb 3, 2005
    #4
  5. cwitt

    Paul Turvill Guest

    Hint: "correct LISP format" has no commas, only spaces.
    ___
     
    Paul Turvill, Feb 3, 2005
    #5
  6. cwitt

    C Witt Guest

    oh my god!..

    not to sound rude or anything, but your not going to help because i put
    in comma's instead of spaces!?! wow.

    I supose others would have posted if i had used a little better grammer
    and punctuation.. not to mention spelling.

    ;|rant over|;

    ((1.0 4.0 0.0)(1.0 3.0 0.0)(1.0 0.0 0.0)(2.0 2.0 0.0)(3.0 3.0 0.0)(3.0
    1.0 0.0))
     
    C Witt, Feb 3, 2005
    #6
  7. cwitt

    Doug Broad Guest

    Lisp is very unforgiving. You need to do your own homework. Otherwise
    you will be unable to use whatever is given to you. Knowing how to
    make a point list is prerequisite to doing anything with it. Sorry. Hard
    facts of life.

    (setq ls (vl-sort ;<-- results in ls

    '((1 4)(1 3)(1 0)(2 2)(3 3)(3 1)) ;<--- list as you want.

    '(lambda (x y)
    (or
    (> (cadr x)(cadr y))
    (and
    (= (cadr x)(cadr y))
    (> (car x)(car y)))))))
     
    Doug Broad, Feb 3, 2005
    #7
  8. cwitt

    cwitt Guest

    that returns a list of:
    ((1 4)(3 3)(1 3)(2 2)(3 1)(1 0))

    the target list was:
    ((1 4)(1 3)(3 3)(2 2)(3 1)(1 0))

    is there another way?
     
    cwitt, Feb 3, 2005
    #8
  9. Try expressing your requirements in concrete
    terms rather than by an example that we must
    reverse engineer.

    Your example suggests that you want to
    sort first by descending Y ordinates, and
    then by ascending X ordinates.

    Is that correct?
     
    Tony Tanzillo, Feb 3, 2005
    #9
  10. cwitt

    Doug Broad Guest

    Yes Tim spotted the error if you want ascending x coordinates. Thanks Tim.


    (setq ls (vl-sort ;<-- results in ls

    '((1 4)(1 3)(1 0)(2 2)(3 3)(3 1)) ;<--- list as you want.

    '(lambda (x y)
    (or
    (> (cadr x)(cadr y)) ;descending y coordinates
    (and
    (= (cadr x)(cadr y))
    (< (car x)(car y))))))) ;<--ascending x coordinates
     
    Doug Broad, Feb 3, 2005
    #10
  11. cwitt

    T.Willey Guest

    No problem. I could've used this little sort a while ago, just couldn't think of how to do it. Thanks for the example.

    Tim
     
    T.Willey, Feb 3, 2005
    #11
  12. cwitt

    cwitt Guest

    Thank you
     
    cwitt, Feb 3, 2005
    #12
  13. cwitt

    cwitt Guest

    Thank you
     
    cwitt, Feb 3, 2005
    #13
  14. cwitt

    T.Willey Guest

    You're welcome.

    Tim
     
    T.Willey, Feb 3, 2005
    #14
  15. cwitt

    Doug Broad Guest

    You're very welcome.
     
    Doug Broad, Feb 3, 2005
    #15
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.