+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Junior Member
    Computer Details
    sathalex's Computer Details
    Operating System:
    Windows
    Computer:
    Asus
    Using
    AutoCAD 2015
    Join Date
    Jul 2016
    Location
    Russia
    Posts
    14

    Default Find the highest and lowest mark from the selected "points"

    Registered forum members do not see this ad.

    Hello!
    In my drawing there are 200 primitives "point", how would I quickly find the highest and the lowest of them?

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    5,930

    Default

    Hi,

    Easily you can do that by retrieving the coordinates of each point then sort them with their Maximum Y coordinate, then finally the first and the last items in the list would be the Highest & Lowest.

  3. #3
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,490

    Default

    If the points have been compiled as a list then
    Code:
    (apply 'max (mapcar 'caddr pt_list))
    (apply 'min (mapcar 'caddr pt_list))
    There are several other metheods available as well. -David
    R12 (Dos) - A2K

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,227

    Default

    Sorting should be avoided when trying to determine the extrema of a point set, as the set need only be processed once. This may therefore be performed with O(n) efficiency, whereas sorting is generally on the order of O(n log n).

    I would therefore suggest something like:
    Code:
    (defun maxmin ( lst / mni mxa zco zmi zmx )
        (setq mni (car lst) zmi (caddr mni) mxa mni zmx zmi)
        (foreach  itm (cdr lst)
            (setq zco (caddr itm))
            (cond
                (   (< zmx zco)
                    (setq mxa itm zmx zco)
                )
                (   (< zco zmi)
                    (setq mni itm zmi zco)
                )
            )
        )
        (list mni mxa)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Junior Member
    Computer Details
    sathalex's Computer Details
    Operating System:
    Windows
    Computer:
    Asus
    Using
    AutoCAD 2015
    Join Date
    Jul 2016
    Location
    Russia
    Posts
    14

    Default

    Quote Originally Posted by Lee Mac View Post
    Sorting should be avoided when trying to determine the extrema of a point set, as the set need only be processed once. This may therefore be performed with O(n) efficiency, whereas sorting is generally on the order of O(n log n).

    I would therefore suggest something like:
    Code:
    (defun maxmin ( lst / mni mxa zco zmi zmx )
        (setq mni (car lst) zmi (caddr mni) mxa mni zmx zmi)
        (foreach  itm (cdr lst)
            (setq zco (caddr itm))
            (cond
                (   (< zmx zco)
                    (setq mxa itm zmx zco)
                )
                (   (< zco zmi)
                    (setq mni itm zmi zco)
                )
            )
        )
        (list mni mxa)
    )
    At the command prompt Error: too few arguments (((

  6. #6
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,382

    Default

    Worked for me

    Code:
    (SETQ LST (LIST (LIST 10 20 30)(LIST 20 20 20)(LIST 10 10 100)))
    (maxmin lst)
    A man who never made mistakes never made anything

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,227

    Default

    Quote Originally Posted by sathalex View Post
    At the command prompt Error: too few arguments (((
    The function is for use in other programs, it does not define an AutoCAD command.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    981

    Default

    Awesome (effective) function Lee,
    Just figured out:
    Why don't write something more global using the same algorithm, like accepting function and list arguments (just like vl-sort), i.e.:

    Code:
    (foo (lambda (r x) (< r x)) '(3 8 9 1 5 6 2 7) )
    -> 1
    where lambda is a test function and takes two arguments for comparing:
    r - item to be returned
    x - comparsion item

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,227

    Default

    Thanks Grrr - as for a generic function, consider the following:
    Code:
    (defun extremum ( cmp lst / rtn )
        (setq rtn (car lst))
        (foreach itm (cdr lst)
            (if (apply cmp (list itm rtn)) (setq rtn itm))
        )
        rtn
    )
    Code:
    _$ (extremum '< '(3 8 9 1 5 6 2 7))
    1
    Code:
    _$ (extremum '(lambda ( a b ) (< (caddr a) (caddr b))) '((1.2 5.7 8.3) (9.4 2.6 0.3) (5.7 6.6 7.2)))
    (9.4 2.6 0.3)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,227

    Default

    Registered forum members do not see this ad.

    Or recursively:
    Code:
    (defun extremum ( cmp lst )
        (   (lambda ( foo ) (if (cdr lst) (foo (car lst) (extremum cmp (cdr lst))) (car lst)))
            (lambda ( a b ) (if (apply cmp (list a b)) a b))
        )
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Want to draw a series of "X" or "l l" lines between 2 points (weld lines)
    By p0peye in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 3rd Dec 2013, 10:58 pm
  2. Replies: 1
    Last Post: 7th Feb 2013, 10:28 pm
  3. Replies: 10
    Last Post: 29th Jan 2013, 08:38 pm
  4. selected objects not showing up as "dashed"
    By streetmike in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 3
    Last Post: 21st Jun 2010, 08:00 pm
  5. Lisp: Extract highest/lowest value from a list
    By ajs in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 12th Feb 2009, 02:58 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts