Longest leg of a Rectangle

Discussion in 'AutoCAD' started by Mark, Nov 3, 2004.

  1. Mark

    Mark Guest

    Hello,

    Would anyone know how I would determine the long leg of a rectangle if I
    already have the points for the rectangle contained in a list. Could this be
    done using plain AutoLisp?

    Thanks,
    Mark
     
    Mark, Nov 3, 2004
    #1
  2. Mark

    Rick Keller Guest

    I would extract the X coordinates and the Y coordinates from the points.
    Subtract one from the other then compare the 2. The larger one is the longer
    one.

    There is probably an easier way... I always seem to do things the hard way.

    Rick
     
    Rick Keller, Nov 3, 2004
    #2
  3. Mark

    Rick Keller Guest

    I would extract the X coordinates and the Y coordinates from the points.
    You should only need 2 diagonal points.
    Subtract one from the other then compare the 2. The larger one is the longer
    one.

    There is probably an easier way... I always seem to do things the hard way.

    Rick
     
    Rick Keller, Nov 3, 2004
    #3
  4. Mark

    BillZ Guest

    Check the distances:

    Command: (setq dslst (list (distance pt1 pt2)(distance pt2 pt3)(distance pt3
    pt4)(distance pt4 pt1)))
    (17.5202 10.088 17.846 10.6433)

    Command: (setq longest (apply 'max dslst))
    17.846

    Command: (setq index (- (length dslst)(length (member longest dslst))))
    2

    This would give you the 3rd element of the point list.

    HTH

    Bill
     
    BillZ, Nov 3, 2004
    #4
  5. Mark

    Jimmy D Guest

    This could work if you assume that pt1 and pt2 aren't by accident the diagonal points of the rectangle!
    I think first you have to find out what lines are parallel to each other and then get the greatest distance?

    Jim
     
    Jimmy D, Nov 3, 2004
    #5
  6. Mark

    Mark Guest

    Thanks all for your help. Actually Jimmy is correct I don't always know in
    what order the point list will be.

    Mark

    diagonal points of the rectangle!
    and then get the greatest distance?
     
    Mark, Nov 3, 2004
    #6
  7. Mark

    BillZ Guest

    I guess it goes to the old saying:

    Assume broken down makes an Ass-u-me.....

    Bill
     
    BillZ, Nov 3, 2004
    #7
  8. Mark

    Tom Smith Guest

    If you take the distances from one point to each of the other three points -
    assuming it's a rectangle and not a parallelogram - then the greatest length
    will be the diagonal and the other two will be the short and long side
    dimensions, regardless of the order of the point list.

    (setq dslst (list (distance pt1 pt2)(distance pt1 pt3)(distance pt1 pt4)))
    (setq dslst (vl-sort dslst '<)) ;ascending order
    (nth 0 dslst) ;short dimension
    (nth 2 dslst) ;long dimension
     
    Tom Smith, Nov 3, 2004
    #8
  9. Mark

    Mark Guest

    Thanks Tom that works!
     
    Mark, Nov 3, 2004
    #9
  10. Mark

    Tom Smith Guest

    Thanks Tom that works!

    No prob. Remember, it won't work if it's not a true rectangle. That would
    require another test.
     
    Tom Smith, Nov 3, 2004
    #10
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.