parralel lines

Discussion in 'AutoCAD' started by mark, Aug 10, 2004.

  1. mark

    mark Guest

    hi,

    to check if two lines are parallel, i have been using
    (if (not (inters a b c d nil))
    where a and b are the endpoints of line 1
    and c d the endpoints of line 2

    what would be the fastest way to check
    if they are parallel to a 1 degree tolerance?

    TIA
     
    mark, Aug 10, 2004
    #1
  2. Try this:

    (defun c:cll (/ l1 l2)
    (setq l1 (ssget "+.:E:S" (list (cons 0 "LINE")))
    l2 (ssget "+.:E:S" (list (cons 0 "LINE")))
    )
    (areparallel (ssname l1 0) (ssname l2 0) 1.0)
    )

    (defun areparallel (l1 l2 fuzz / o1 o2 a1 a2 )
    (vl-load-com)
    (setq
    o1 (vlax-EName->vla-Object L1)
    o2 (vlax-EName->vla-Object L2)
    a1 (rem (rtd (vla-get-angle o1)) 180)
    a2 (rem (rtd (vla-get-angle o2)) 180)
    )
    (<= (abs (- a2 a1)) fuzz)

    )

    (defun RTD (a) ;Radians to degrees conversion
    (* 180.0 (/ a pi)))
     
    Allen Johnson, Aug 10, 2004
    #2
  3. Slight correction, in case the angles calculate out to 180 and 0:

    (defun areparallel (l1 l2 fuzz / o1 o2 a1 a2 )
    (vl-load-com)
    (setq
    o1 (vlax-EName->vla-Object L1)
    o2 (vlax-EName->vla-Object L2)
    a1 (rem (rtd (vla-get-angle o1)) 180)
    a2 (rem (rtd (vla-get-angle o2)) 180)
    )
    (or (equal a2 a1 fuzz)
    (equal (abs (- a2 a1)) 180 fuzz)
    )
    )
     
    Allen Johnson, Aug 10, 2004
    #3
  4. mark

    mark Guest

    thanks
     
    mark, Aug 10, 2004
    #4
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.