Aranging a list of points witch is closesed to a certain point.

Discussion in 'AutoCAD' started by Marcel Janmaat, Apr 15, 2004.

  1. I have a certain point selected within a closed area and the four points of
    this closed area itself in a list.

    For example;

    (setq pnt (25122.7 10159.6 0.0))
    and
    (setq hpl ((30830.6 14548.3) (27539.0 18829.2) (21831.2 14440.5) (25122.7
    10159.6))).

    4 ____________ 3
    | |
    | |
    | . pnt |
    1 |____________| 2

    I'm trying to figureout how to arange this list in a (backward clockwise)way
    so that the the point in the list 'closesed pnt, comes first in the list,
    then 2 then 3 and then 4.

    Can someone please give me some sugestions on this?

    MJ
     
    Marcel Janmaat, Apr 15, 2004
    #1
  2. Interesting challenge. (Your "pnt" is the same as one of your four corners,
    and those four make a shape pretty different from the diagram, but that
    doesn't affect the general idea.) Without spelling out all the coding for
    it, this approach might work:

    Extract the four point-lists from the "hpl" list (presumably with the
    car/cdr/etc. functions), and save them to variables, for example
    cornera/cornerb/etc.

    Use getdist to measure the distances from "pnt" to each of the corners, and
    set them to variables, for example dista/distb/etc.

    Compare the values of dista/distb/etc., to find the shortest. (But what
    happens if there are two equal shortest distances?)

    To establish the counterclockwise sequence, set the UCS Origin to "pnt" and
    rotate the UCS about the Z axis so that zero degrees is toward that closest
    corner. Then use getangle to find the angles from "pnt" to each other
    corner, and compare the values to put them in ascending order.

    This might not work right if the quadrilateral isn't convex at all corners
    (e.g. a boomerang/chevron shape), depending on where "pnt" lies within it.

    Just a start....

    Kent Cooper, AIA


    of this closed area itself in a list.
     
    Kent Cooper, AIA, Apr 15, 2004
    #2
  3. Marcel Janmaat

    BillZ Guest

    (setq hpl (list '(30830.6 14548.3) '(27539.0 18829.2) '(21831.2
    14440.5)' (25122.7 10159.6)))

    Set pnt to point other than contents of hpl and inside area defined by hpl list.

    (setq pnt '(26322.4 13956.9 0.0))

    Now:

    (setq dlst (mapcar '(lambda (p)(distance p pnt)) hpl))
    (4546.87 5021.91 4517.12 3982.29)

    Command: (setq mnd (apply 'min dlst))
    3982.29

    Command: (setq loc (- (length dlst)(length (member mnd dlst))))
    3
    (setq p1 (nth loc (nth cnt dlst)) ;point that returned minimum dist.

    Maybe you can take it from there? :)


    Bill
     
    BillZ, Apr 15, 2004
    #3
  4. This should do, I hope I really unterstood what you need;-)

    (defun test(pt corners / dists nearest)
    (setq nearest(apply'min(setq dists(mapcar(function
    (lambda(corner)(distance pt corner)))corners))))
    (while(/= nearest(car dists))
    (setq dists(append(cdr dists)(list(car dists))))
    (setq corners(append(cdr corners)(list(car corners))))
    )
    corners
    )

    (test '(25122.7 10159.6)'((30830.6 14548.3) (27539.0 18829.2) (21831.2
    14440.5) (25122.7 10159.6)))

    => ((25122.7 10159.6) (30830.6 14548.3) (27539.0 18829.2) (21831.2 14440.5))

    Axel
     
    Axel Strube-Zettler, Apr 15, 2004
    #4
  5. Marcel Janmaat

    BillZ Guest

    I couldn't just leave it at that.

    This should work with simple point picks.

    (defun point_distance (/ dlst loc mnd nwlst p1 p2 ptlst tmplst)
    (setvar "blipmode" 1)
    (while (setq Pt (getpoint "\npick points then hit < enter >: "))
    (setq PtLst (cons Pt PtLst))
    )

    (setq PtLst (reverse PtLst)
    p1 (getpoint "\nPick reference point. ")
    dlst (mapcar '(lambda (p)(distance p p1)) PtLst) ;distance list
    mnd (apply 'min dlst) ;minimum dist
    loc (- (length dlst)(length (member mnd dlst))) ;index number
    p2 (nth loc PtLst) ;point that returned minimum dist
    nwlst (member p2 PtLst)
    tmplst PtLst
    )
    (repeat (- (length tmplst)(length nwlst))
    (setq nwlst (append nwlst (list (car tmplst))) tmplst (cdr tmplst))
    )
    (setq nwlst (cons p1 nwlst)
    )
    (setvar "blipmode" 0)
    nwlst
    )

    Bill
     
    BillZ, Apr 15, 2004
    #5
  6. I don't understand parts of this line from BillZ's first version:
    I don't see where "cnt" is defined. It should be an integer coming from
    somewhere, to be in that location as an argument to "nth." And shouldn't
    the "nth" function be applied to "hpl" instead of to "dlst"? The "nth"
    function applied to "dlst" would return a real (that's what "dlst" is made
    up of), but what you want it to return is a point (which is what "hpl" is
    made up of).

    Kent Cooper, AIA
     
    Kent Cooper, AIA, Apr 15, 2004
    #6
  7. Marcel Janmaat

    BillZ Guest

    One little mistake and everybody notices... :)

    That's what happens when you cut & paste from another program and don't check it.

    I'll edit it.

    Bill
     
    BillZ, Apr 15, 2004
    #7
  8. Thanx for the usefull tips.

    I've got what i needed.
     
    Marcel Janmaat, Apr 16, 2004
    #8
  9. Marcel Janmaat

    BillZ Guest

    You're welcome!

    Bill
     
    BillZ, Apr 16, 2004
    #9
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.