Intersection between Arc and Line

Discussion in 'AutoCAD' started by Roel Westhoff [W4], Dec 21, 2004.

  1. Hi all,

    Is there a function in vlisp that generates an intersection point between an arc and line. I looked at the doc's but could not find anything

    Roel Westhoff
     
    Roel Westhoff [W4], Dec 21, 2004
    #1
  2. Roel Westhoff [W4]

    Dann Guest

    Returns x,y,z of all Intersect points between 2 objects as a list:

    ;>code
    (vl-load-com)

    ;;The following gets and returns a selected object in Activex format
    ;;******************************************************************

    (defun objsel ($prompt / ent obj)
    ;;usage = (setq obj(objsel "Select Object: "))
    (setq ent (car (entsel $prompt)))
    (if (/= ent nil)
    (setq obj (vlax-ename->vla-object ent))
    (princ "No Object Selected")
    )
    obj
    ;;returns result for use in calling program
    )

    ;;_________________
    ;;end tools section
    ;;_________________

    (defun db_int (/ obj1 obj2 @int int)
    (setq obj1(objsel "Select First Object: "))
    (setq obj2(objsel "Select Second Object: "))
    (setq @int(vla-IntersectWith obj1 obj2 acExtendBoth))
    (setq int(vlax-Safearray->List (vlax-Variant-Value @int)))
    int
    )

    ;;Returns x,y,z of all Intersect points between 2 objects as a list
    ;;usage(setq int(db_int))
    ;<code

    Hi all,

    Is there a function in vlisp that generates an intersection point between an arc and line. I looked at the doc's but could not find anything

    Roel Westhoff
     
    Dann, Dec 21, 2004
    #2
  3. Roel Westhoff [W4]

    David Bethel Guest

    ;;;++++++++++ 2D Intersections Of Line & Arc ( Circle ) ++++++++++++++++
    ;;;ARG -> LINE_ename ARC_ename ( CIRCLE or ARC )
    ;;;RET -> nil or List_Of_Points
    ;;;ERROR = None

    (defun inter_line_arc (line arc / p10 p11 cen rad ppd ppt dis ips p2d)

    (setq p2d (lambda (p) (list (car p) (cadr p))))

    (and (setq p10 (p2d (cdr (assoc 10 (entget line))))
    p11 (p2d (cdr (assoc 11 (entget line))))
    cen (p2d (cdr (assoc 10 (entget arc))))
    rad (cdr (assoc 40 (entget arc))))
    (not (equal p10 p11 1e-14))
    (setq ppt (inters p10 p11 cen (polar cen (+ (angle p10 p11) (*
    pi 0.5)) rad) nil)
    ppd (distance cen ppt))
    (<= ppd rad)
    (setq dis (sqrt (- (* rad rad) (* ppd ppd))))
    (if (equal dis ppd 1e-14)
    (setq ips (list ppt))
    (setq ips (list (polar ppt (angle p10 p11) dis)
    (polar ppt (angle p11 p10) dis)))))
    ips)



    -David
     
    David Bethel, Dec 21, 2004
    #3
  4. Roel Westhoff [W4]

    Joe Burke Guest

    Dann,

    Your db_int function will return an Active X error: invalid index, when no
    intersections are found.

    Barring that hiccup, process the flat coordinate list into a usable list of points.
    Something like this. Which returns either a point (one intersection), a point list,
    or nil given no intersections found.

    (defun db_int (/ obj1 obj2 coord ptlst)
    (setq obj1 (objsel "Select First Object: "))
    (setq obj2 (objsel "\nSelect Second Object: "))
    (setq coord (vlax-invoke obj1 'IntersectWith obj2 acExtendBoth))
    (repeat (/ (length coord) 3)
    (setq ptlst (cons (list (car coord) (cadr coord) (caddr coord)) ptlst))
    (setq coord (cdddr coord))
    )
    (if (= 1 (length ptlst))
    (car ptlst)
    (reverse ptlst)
    )
    )

    Joe Burke
     
    Joe Burke, Dec 21, 2004
    #4
  5. Dann,

    Thx Was not aware of the new commands (vla-...)
    Have to look into it.

    Roel
    "Dann" <NoneSpecified> schreef in bericht Returns x,y,z of all Intersect points between 2 objects as a list:

    ;>code
    (vl-load-com)

    ;;The following gets and returns a selected object in Activex format
    ;;******************************************************************

    (defun objsel ($prompt / ent obj)
    ;;usage = (setq obj(objsel "Select Object: "))
    (setq ent (car (entsel $prompt)))
    (if (/= ent nil)
    (setq obj (vlax-ename->vla-object ent))
    (princ "No Object Selected")
    )
    obj
    ;;returns result for use in calling program
    )

    ;;_________________
    ;;end tools section
    ;;_________________

    (defun db_int (/ obj1 obj2 @int int)
    (setq obj1(objsel "Select First Object: "))
    (setq obj2(objsel "Select Second Object: "))
    (setq @int(vla-IntersectWith obj1 obj2 acExtendBoth))
    (setq int(vlax-Safearray->List (vlax-Variant-Value @int)))
    int
    )

    ;;Returns x,y,z of all Intersect points between 2 objects as a list
    ;;usage(setq int(db_int))
    ;<code

    Hi all,

    Is there a function in vlisp that generates an intersection point between an arc and line. I looked at the doc's but could not find anything

    Roel Westhoff
     
    Roel Westhoff [W4], Dec 21, 2004
    #5
  6. David,

    Looks good. Segmenting an arc .. quiet neet
    Thx in advance

    Roel
     
    Roel Westhoff [W4], Dec 21, 2004
    #6
  7. Roel Westhoff [W4]

    TCEBob Guest

    David,

    Every time I think I know a little about lisp I get humbled in this group. First
    read-through I thought, Oh oh, a typo -- (setq p2d (lambda ... . But, what the
    hay, I ran it. It works. I wonder if you could explain the difference between
    the (setq and a (defun in this case?

    Best wishes for the season,
    The ever humble

    rs
     
    TCEBob, Dec 23, 2004
    #7
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.