Calling all Math Wiz's - vlax-curve-getfirstderiv

Discussion in 'AutoCAD' started by Darren J. Young, Apr 23, 2004.

  1. Being that my math skills have deteriorated due to lack of sufficient
    use...

    Would someone be so kind as to explain what the derivative is as it
    relates to the (vlax-curve-getfirstderiv) and (vlax-curve-
    getsecondderiv) functions?


    Thanks much!

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 23, 2004
    #1
  2. I assume first derive would be the slope at a given point, and the second
    Unless you need to massage and molest that number a little bit I don't
    see it.

    I checked a point on a spline's curve right at it's tangent point to a
    horizontal line and the function returns back a point way off in space
    somewhere.

    Wait....wait.....wait....there's it is. Take the angle from 0,0,0 (WCS)
    to the point returned by the first derivative and you get the angle at
    that point.

    Thanks much! That was quick!

    I guy that was at one of my classes at AU a couple years ago just asked
    me that (we were talking about it today) and I just happened to be
    working on a project today myself where I needed that as well. You
    killed to birds with one stone!

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 23, 2004
    #2
  3. Darren J. Young

    Jamie Duncan Guest

    I can still do some calculus - without having to consult my university
    texts. I can still derive simple beam equations etc, forget pdeq's,
    anything complicated overtaxes my meagre memory resources...

    Glad I could help.


    --
    Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)
     
    Jamie Duncan, Apr 24, 2004
    #3
  4. Darren J. Young

    John Uhden Guest

    Do a Google search in the Groups category. The function will return various
    information depending on the object selected.
     
    John Uhden, Apr 26, 2004
    #4
  5. No, that's GetParameterAtXxxxx that's interpreted
    differently for each type of curve class.

    The first and second derivatives are WCS vectors
    that describe the tangent and normal directions
    of the curve at a given point on it.
     
    Tony Tanzillo, Apr 26, 2004
    #5
  6. Darren J. Young

    Doug Broad Guest

    Clarifications (assuming WCS):

    Vlax-curve-getfirstderiv and
    vlax-curve-getsecondderiv both return vectors.
    They are not always perpendicular to one another.
    Neither is the second derivative always normal
    to the curve

    To simplify the discussion, the following terms
    are defined:
    D1 = first derviative vector returned from
    vlax-curve-getfirstderiv
    |D1|= length of D1
    D2 = second derivative vector returned from
    vlax-curve-getfirstderiv
    |D2|= length of D2
    PT= the point at which the derivatives are
    taken on the curve.
    PARAM = second argument to the functions.
    Return value of (vlax-curve-getparamatpoint <curveobj> PT)

    In general:

    1. D1 is always tangent to the curve at PT.
    2. D1 always indicates the direction of the curve at PT.
    3. D2 always indicates the general direction of concavity.
    4. |D2| is proportional to the sharpness of the curve at
    that point. The faster the curve changes direction the
    greater |D2| is.
    5. Inflection points on the curve can be found where
    |D2| is 0.

    Specifically for circular curves:
    1.|D1|=|D2|=radius of curvature.
    2.D2 from PT ends at center.
    3.D1 is normal to D2
    4.PT+D1+D2(shorthand for D1 and D2 placed tip to tail
    from PT) ends on the curve or where the curve would
    be if it continued.

    Specifically for elliptical curves:
    1. D2 from PT ends at the centroid of the ellipse.
    2. D1 is normal to D2 at the quadrant points.
    3. |D1| and |D2| are each the half axis lengths at the
    quadrant points.
    4. PT+D1+D2 ends on the curve or where the curve would
    be if it continued.

    Specifically for line segments:
    1.|D1|= length of the line.
    2.|D2|= 0
    3.D2 = (0.0 0.0 0.0)

    Specifically for splines:
    1. PT+D1+D2 usually does not end on the spline.

    A value of (0.0 0.0 0.0) for D2 indicates that PT
    is on a straight line segment or at an inflection point.

    The above is derived from solely on my observation. I have
    seen no documentation explaining these conclusions.

    Regards,
    Doug
     
    Doug Broad, Apr 26, 2004
    #6
  7. Darren J. Young

    John Uhden Guest

    Thank you, Doug. That's probably the most exhaustive explanation posted
    anywhere. Even if some of it is incorrect, it can be used as a jump-start for
    experimentation, which is all I have bothered to do. I've used them only
    once... in the last @cv_inside function, which attracted no interest.
     
    John Uhden, Apr 27, 2004
    #7
  8. Darren J. Young

    Doug Broad Guest

    You're welcome John. Be sure to point out anything you
    know is incorrect. Here are some functions to make investigation
    easier. And I don't know about lack of interest in @cv_inside.
    I thought it was very nice.

    And several other conclusion:

    In general

    6. Inflection points only occur on continuous splines, not on
    piecewise functions like plines unless spline fit.

    7. The length |D1| is exactly equal to the arclength|length of
    the curve between PARAM and PARAM+1.


    (defun c:test ()
    ;;No localization to allow for examination of
    ;;variables after test.
    (command "ucs" "")
    (command "osnap" "non")
    (vl-load-com)
    (setq obj (vlax-ename->vla-object(car(entsel))))
    (while
    (setq pt (osnap (getpoint "\nPick point on object: ") "nea"))
    (setq param (vlax-curve-getparamatpoint obj pt))
    (setq d1 (vlax-curve-getfirstderiv obj param)
    d2 (vlax-curve-getsecondderiv obj param))
    (command "line" pt (mapcar '+ pt d1) "")
    (command "line" pt (mapcar '+ pt d2) "")
    (print (strcat "|D1|=" (rtos (distance '(0 0 0) d1) 2 3)
    "|D2|=" (rtos (distance '(0 0 0) d2) 2 3)
    ))
    )
    (princ))

    ;;LENGTH OF CURVE BETWEEN PARAM AND PARAM+1
    (defun c:L1 ()
    ;;Assumes one has run test. Purpose: To determine the
    ;;length of the curve to PARAM + 1
    (setq pt2 (vlax-curve-getpointatparam obj (+ param 1.0))
    dist1 (vlax-curve-getdistatpoint obj pt)
    dist2 (vlax-curve-getdistatpoint obj pt2)
    len (- dist2 dist1)
    )
    )

    ;;POINT AT PARAM+1
    (defun c:NP ()
    (command "point" (vlax-curve-getpointatparam obj (+ param 1.0))))

    Regards,
    Doug



    <snip>
     
    Doug Broad, Apr 27, 2004
    #8
  9. Doug - Re the second derivative, that's absolutely correct.
    It is only normal to first order curves, which is natural
    since their curvature is constant, and they have no
    inflection points.
     
    Tony Tanzillo, Apr 27, 2004
    #9
  10. Darren J. Young

    Doug Broad Guest

    Correction:

    Conclusion 7 is only true for curves(arcs, circles, splines..)
    Length |D1| is equal to length of a line as stated earlier.
     
    Doug Broad, Apr 27, 2004
    #10
  11. It's almost a full time job just documenting all the knowledge and
    useful tidbits of information everyone posts here.

    I'm seriously considering going back to school for a degree in
    mathematics. My lack of knowledge in this area is sometimes crippling.

    I don't even want to admit how long it took for me to come up with a
    formula to give the start and end angles (from zero) of an arc given 3
    coordinates (Start, mid, and end) of an arc.

    --
    Darren J. Young
    CAD/CAM Systems Developer

    Cold Spring Granite Company
    202 South Third Avenue
    Cold Spring, Minnesota 56320

    Email:
    Phone: (320) 685-5045
    Fax: (320) 685-5052
     
    Darren J. Young, Apr 27, 2004
    #11
  12. Darren J. Young

    David Kozina Guest

    OK, now I've got a question... probably a simple one.

    Given the simple straight line diagram below:
    (No arcs or spline curves are involved in this case, but the Obj line could
    be at any angle)

    + A
    ,Obj |
    Start +==============+ End
    |
    + B

    Start = (vlax-curve-GetStartPoint Obj)
    End = (vlax-curve-GetEndPoint Obj)

    Lngth = (vlax-curve-GetDistAtParam Obj 1)

    UnitDirectionVector[Start->End] = D1
    (mapcar
    '(lambda (ord)
    (/ ord Lngth)
    )
    (vlax-curve-GetFirstDeriv Obj 1)
    )

    Am I correct regarding the above, so far?

    If so, are the Unit Vector Normals to the direction vector?:

    N1 to UnitDirectionVector =
    (list (cadr D1) (- (car D1)) 0)

    N2 to UnitDirectionVector =
    (list (- (cadr D1)) (car D1) 0)


    Given a distance X, normal to the end point, can points A and B then be
    calculated as:

    A =
    (mapcar '+
    End
    (mapcar
    '(lambda (ord)
    (* X ord)
    )
    N1
    )
    )

    B =
    (mapcar '+
    End
    (mapcar
    '(lambda (ord)
    (* X ord)
    )
    N2
    )
    )


    Am I making this too complicated?
    Or am I on the right track?

    Thanks for any input regarding the above.

    Best regards,
    David Kozina
     
    David Kozina, May 13, 2004
    #12
  13. Darren J. Young

    Doug Broad Guest

    Hi David,
    Since the endparam for a line is the length of the line,
    your calculation for lngth would be incorrect.

    Instead
    lngth = (distance start end)
    or
    lngth = (vlax-curve-getdistatparam obj (vlax-curve-getendparam obj))
    or
    lngth = (distance (vlax-curve-getfirstderiv obj) '(0 0 0))

    Also it is possible to get a distance on the line past the endparam
    of the curve.

    Regards,
    Doug

    <snip>
     
    Doug Broad, May 13, 2004
    #13
  14. Darren J. Young

    David Kozina Guest

    Doug,

    Many thanks for the information.
    Now I have more questions... :)

    I seem to be confused regarding the term "Parameter", used with respects to
    the functions

    vlax-curve-getStartParam
    vlax-curve-getEndParam
    vlax-curve-getDistAtParam
    vlax-curve-getParamAtDist
    vlax-curve-getParamAtPoint
    vlax-curve-getPointAtParam

    For some reason I was under the impression that the parameter was a
    percentage of the total length - IOW, 0.00 would be the parameter at the
    start point, and 1.00 at the end point, 0.50 at the midpoint, etc. (Which,
    would've made the first two functions above irrelevant, huh?)


    So... just what *is* the relationship between distances, total lengths, and
    parameters? I think such an explanation (or direction to a thread
    discussing this) would be very helpful to me.

    Also, you provided 3 methods for determining the length of the line, and I
    can think of at least one more via

    (vlax-get-property Obj 'Length)

    (But only for lines and polylines, as in this case, not for other types of
    'curves', (splines, ellipses, etc), correct?)

    Has anyone determined via any type of testing which of these multiple
    methods, is the most efficient? (Assuming you already have determined what
    your "Obj" is and have also obtained the Start and End points)


    <Here's the intended use for this particular case: Please feel free to
    kibbitz>
    What I'm trying to do in this case is extract 2 points by allowing the user
    to draw a line (via the LINE command, so they can have easy access to DDE,
    osnaps, etc, without a lot of extra fuss)

    From that one object, I can extract the 2 end points, as well as calculate
    additional points, which will allow me to draw additional objects and then
    delete the original (construction) line object.

    (In a previous iteration of this routine, I was using the getpoint function,
    and then calculating additional points mathematically (via polar, angle,
    dist, etc) - but since the vlax-curve-* functions require an object, using a
    disposable 'construction' object seemed to be a better way to go about it -
    and allow me some practice with these newer functions before trying to
    tackle bigger and more complex things.)

    I would really appreciate knowing if you consider this M.O. to be
    appropriate in view of the newer vlax-curve-* functionality. Again, thanks
    for the assistance.

    Best regards,
    David Kozina
     
    David Kozina, May 14, 2004
    #14
  15. Darren J. Young

    Doug Broad Guest

    Hi David,

    It would have been consistent if the parameters had been
    implemented as you expected. It is however more complicated.
    Each type of curve has its own parametric meaning. They do
    make sense once you accept the differences.

    The best way is to learn by experiment. As I was looking
    into it, I wrote a little program to give me feedback so that
    I could understand the whole issue. Then I drew an example
    of each type of curve and examined the returns.

    Here are a few functions that might jumpstart your investigation.
    I also created some to draw the first and second derivatives
    from the picked point so that I could begin to understand things.
    Look for those in my answer to John Uhden.

    ;;pardon me for the short names. These have no error
    ;;handling. Pick the object first and then use gs and gp
    ;;Code untested. Watch out.

    (vl-load-com)
    ;;get object
    (defun c:go ()(setq obj (vlax-ename->vla-object (car (entsel)))))

    ;;get startparam
    (defun c:gs ()(vlax-get-startparam obj))

    ;;get paramatpoint
    (defun c:gp()(vlax-get-paramatpoint obj (osnap (getpoint "\n Pick point on object: ")
    "nea"))

    For arcs and circles, I think you will find that the parameter is an angle. For
    lines, it is the distance from the start point. Positive is toward the end of the line.

    Does that help?
     
    Doug Broad, May 14, 2004
    #15
  16. Darren J. Young

    David Kozina Guest

    Doug,

    Yes, it helps. Thanks yet again.

    Still curious as to how you or others consider the manner that I'm
    attempting to implement said curve functions. Good? Bad? Ugly? :)

    Seems like they are fairly easy to use - but only when there is some sort of
    existing object geometry to work off of - IOW, not too good for pure
    geometrical/mathematical point calculations, as you can do with dist, angle,
    and polar, etc.

    Best regards,
    David Kozina
     
    David Kozina, May 14, 2004
    #16
  17. Darren J. Young

    Doug Broad Guest

    David,

    Your code looks fine. I'm still a little vague on how you
    will be using this. I typically have used dist, angle, polar,
    and mapcar to create parallel and perpendicular geometry
    (say for rectangles, duct transitions, duct double-line...)

    It does seem like the vlax-curve-xxx functions could have
    some good applications when the baseline curve is not
    straight. Perhaps others will chime in. The age of the
    thread may limit participation however.

    Regards,
    Doug
     
    Doug Broad, May 15, 2004
    #17
  18. Darren J. Young

    Mark Propst Guest

    " not too good for pure

    Unless I'm mistaken, you could say that even stronger...
    "they ain't no good at all" for pure calculations
    they're absolutely only useful if you have an object, since they require an
    object for input argument.
    If you just have a trig problem you just solve it with trig funcs.
    But you knew that.
    :)
     
    Mark Propst, May 15, 2004
    #18
  19. Darren J. Young

    David Kozina Guest

    <vox>
    "Vlax-curve functions - they're *so* good you'll wish you had an object to
    use them on..."
     
    David Kozina, May 15, 2004
    #19
  20. Darren J. Young

    David Kozina Guest

    this.


    Just calculating a few points to draw a steel HSA using a couple of mlines
    placed perpendicular to each other :) And it worked just fine, too, I might
    add.

    Next up will be a more complicated Bolt routine - mostly due to the number
    of options I need to incorporate, as well as trying to work out the best
    'logic flow' among them.

    However, the actual creation/drawing of the bolts, mlines, block inserts,
    ought to be cake now...


    I typically have used dist, angle, polar,

    mlines, man, mlines... ;)
    (OK, maybe the duct transitions with mlines would be a little tricky - but,
    show me a picture of what you're talking about...)


    I wish Vladimir would stop by and hold some more analytical geometry
    classes...


    Best regards,
    David Kozina
     
    David Kozina, May 15, 2004
    #20
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.