Find the midpoint of an arc

Discussion in 'AutoCAD' started by swragan, Oct 18, 2004.

  1. swragan

    swragan Guest

    I use a lisp function that inserts an arc through three points obtained by user input. The arc is placed with:

    (command ".arc" p3 p2 p1 )

    Then a block is placed on the arc with:

    (Command ".INSERT" thisblock "scale" sfactor p2 ang2)

    The problem is that I want the block placed on the midpoint of the arc. But point P2 is not necessarly the midpoint, only a point on the arc. If I turn on midpoint snap, my block sometimes winds up on another line or object.

    How can I find the midpoint of the just placed arc, and put the blolck there?
     
    swragan, Oct 18, 2004
    #1
  2. swragan

    James Allen Guest

    After the arc command, you can use (entget (entlast)) to get the arc's dwf
    properties. Then you can calculate the mid from the center, radius, start
    angle, and end angle properties. In the process you will also calculate the
    mid angle, which you may also want.
     
    James Allen, Oct 18, 2004
    #2
  3. swragan

    Jeff Mishler Guest

    Use this function:

    (defun midPtarc (arc / arcList radius ctrPt startPt endPt midChrd mid)
    (setq arcList (entget arc)
    radius (cdr (assoc 40 arcList))
    ctrPt (cdr (assoc 10 arcList))
    startPt (polar ctrPt (cdr (assoc 50 arcList)) radius)
    endPt (polar ctrPt (cdr (assoc 51 arcList)) radius)
    midChrd (mapcar '* (mapcar '+ startpt endpt) '(0.5 0.5 0.5))
    mid (polar ctrPt (angle ctrPt midChrd) radius)
    )
    )

    Like this:

    (command ".arc" p3 p2 p1 )
    (setq midPt (midPtarc (entlast)))
    (Command ".INSERT" thisblock "scale" sfactor midPt ang2)
     
    Jeff Mishler, Oct 18, 2004
    #3
  4. Jeff, I'm surprised ;)

    ; return the midpoint of an object
    ; that has start and end parameters
    (defun objectMidpoint (object)
    (vlax-curve-getpointatparam
    object
    (/
    (+ (vlax-curve-getstartparam object)
    (vlax-curve-getendparam object) )
    2.0
    )
    )
    )
     
    Jason Piercey, Oct 18, 2004
    #4
  5. swragan

    Jeff Mishler Guest

    I started to post my toolbox function that looks nearly identical to yours,
    but it appeared that the OP is fairly new to autolisp so I figured I'd post
    the standard lisp way........

    You probably know MY preferred method.... ;-)

    --
    Jeff
    check out www.cadvault.com
     
    Jeff Mishler, Oct 18, 2004
    #5
  6. swragan

    swragan Guest

    Thanks, that works perfect!!


    Steve
     
    swragan, Oct 18, 2004
    #6
  7. swragan

    swragan Guest

    Posted by Jeff:

    "it appeared that the OP is fairly new to autolisp "

    Yes, you guessed that right. I tried to figure out how to do this by searching the help files, but I didn't get very far.

    Steve
     
    swragan, Oct 18, 2004
    #7
  8. swragan

    James Allen Guest

    Guess I should learn to post a <little> more, even when attempting to help
    educate. Got'a little more learning to do myself... :)

    James
     
    James Allen, Oct 19, 2004
    #8
  9. swragan

    Jeff Mishler Guest

    Actually, you could look at your response as Day 1 of a class....you explain
    the steps needed to accomplish the task.
    I kind of read into the question that the OP may, or may not, have a grasp
    of lisp manipulation so I added Day 2: How to apply the methods...of course,
    the days were only 6 minutes apart...this was a crash course ;-)
    Then Jason jumps in and shared Day 3: How to accomplish the same thing using
    Vlisp/ActiveX...

    That's what I call educating......

    It strange.....depending on my mood, the actual question asked and how it
    was asked, and current workload I'll post something similar to what you did
    all the way to a full blown working application
     
    Jeff Mishler, Oct 19, 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.