See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: vlax-curve-... functions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Active Member David.Hoole's Avatar
    Join Date
    2000-12
    Location
    Yorkshire
    Posts
    84
    Login to Give a bone
    0

    Default vlax-curve-... functions

    Hi folks

    I'm trying to reproduce the function of the AutoCAD MEASURE command to insert blocks along a polyline. I want to insert the blocks perpendicular to the curve & increment attribute values in a very specific pattern along the way.
    I'm sure I'm missing something, but how do I get the angle of the line at a particular distance?
    I think this has something to do with (vlax-curve-getParamAtPoint ... ) but I'm not bright enough to figure out the relationship.

    Thanks in advance.

  2. #2
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    0

    Default Re: vlax-curve-... functions

    Hi David,
    I wrote a tiny "essay" on VLAX-CURVE functions here that might help you get started.

    If no one beats me to it I'll get back with a suggestion for the perp to object problem later.

  3. #3
    Active Member David.Hoole's Avatar
    Join Date
    2000-12
    Location
    Yorkshire
    Posts
    84
    Login to Give a bone
    0

    Default Re: vlax-curve-... functions

    Thanks Stig

    Excellent essay! I look forward to your suggestion for the 'perp' problem (or anybody elses!). Only solution I can see at the moment is to approximate the angle by getting points on the curve at either side of the insertion point, but this seems a bit clunky.

  4. #4
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    1

    Default Re: vlax-curve-... functions

    Thanks David.

    Quote Originally Posted by David.Hoole
    Only solution I can see at the moment is to approximate the angle by getting points on the curve at either side of the insertion point, but this seems a bit clunky.
    You can get the angle directly with vlax-curve-getFirstDeriv. It will return the direction vector at the specified parameter along a curve object. For straight segments in a pline, it'll be equal to the normalized segment, and for curved segments, it'll be equal to the tangent.

    I know vlax-curve-getSecondDeriv will get the angle you're after directly (= normal to curve) but I haven't figured out how to apply it to straight segments. Maybe someone here can explain if it's even possible?

    Below is a rewrite of the measurePline function from the link above that only uses the first derivates. It'll get the parameters and first derivates from each measured point and draw two lines; one along the direction vector and one rotated 90 degrees from the direction vector. To apply it to block insertions, simply use the points and angles.

    Note: Remember to turn off running osnaps before running it.

    Code:
    (defun measurePline (obj divDist / endParam dist totLen pt par fder)
      (command "UNDO" "Begin")
      (setq dist 0.0 orig '(0.0 0.0 0.0))
      (setq endParam (vlax-curve-getEndParam obj)
            totLen   (vlax-curve-getDistAtParam obj endParam)
      )
      (while (<= dist totLen)
        (setq pt   (vlax-curve-getPointAtDist obj dist)
              par  (vlax-curve-getParamAtDist obj dist)
              fder (vlax-curve-getFirstDeriv obj par)
              dist (+ dist divDist)
        )
        (cond (pt
               (command "POINT" pt)
               ;; this will draw a line along the direction vector
               (command "LINE" pt (mapcar '+ pt fder) "")
               ;; .. and this will rotate the direction vector 90 degrees
               (command "LINE" pt (polar pt (+ (angle orig fder) (/ pi 2.0))(distance pt (mapcar '+ pt fder))) "")
              )
        )
      )
      (command "UNDO" "End")
    )

  5. #5
    Active Member David.Hoole's Avatar
    Join Date
    2000-12
    Location
    Yorkshire
    Posts
    84
    Login to Give a bone
    0

    Default Re: vlax-curve-... functions

    Thanks Stig

    Exactly what I needed. I'll make good use of this lesson!

  6. #6
    AUGI Addict sinc's Avatar
    Join Date
    2004-02
    Location
    Colorado
    Posts
    1,986
    Login to Give a bone
    1

    Default Re: vlax-curve-... functions

    No, you can't use the second derivative on line segments. There's an explanation in linear algebra, and a possibly simpler one in topology once you reach the point where you can understand all the 3-ball and 2-sphere stuff, but the easiest explanation might be a sort of real-world analogy. AutoCAD works in 3-D, and most of us probably had our first real experience with derivatives in physics anyway, with stuff like v = xdt and so forth, so that approach might be the best.

    Let's imagine a polyline as being the path a ball has travelled. As you remember from physics, a derivative is a rate of change. So, since we're assuming the polyline represents the position of the ball over time, the first derivative would be the velocity the ball is travelling at any particular instant in time. For straight segments, this velocity vector is in the same direction as the direction of travel. For curves, this is in a line tangent to the curve at that point. AutoCAD returns this direction vector, or first derivative, as simply a coordinate, the endpoint of a vector; the vector is assumed to start at (0,0,0). And, niftily enough, it looks like AutoCAD defined things so that the length of the vector is the length of the line for line segments, and the radius of the curve for arcs. (I wouldn't recommend using this function to get lengths or radii, though... It might have just turned out that way in the few items I checked in some poking around...)

    Now, let's look at the second derivative. We remember from physics that this is acceleration, or how much the ball's velocity is changing. In other words, the second derivative is another directional vector, this one showing which way some invisible force would need to push the ball to make it travel along our polyline. And, again from our physics, this directional acceleration vector would be in the plane of the curve, and perpendicular to the direction of travel. In AutoCAD terms, the direction of this vector is perpendicular to the curve, toward its radius. And again, because of the way the math works, the length of the direction vector is equal to the radius of the curve.

    However, with lines, the direction of travel is not changing. In physics terms, the lateral acceleration is 0. This implies the second derivative of a line segment must ALWAYS be 0, regardless of its direction. (Conversely, the second derivative of a curve must ALWAYS be non-zero.)
    Last edited by sinc; 2004-07-14 at 02:41 AM.

  7. #7
    100 Club
    Join Date
    2000-12
    Posts
    126
    Login to Give a bone
    0

    Default Re: vlax-curve-... functions

    Brilliant explanation, mr. Sincovec! Thank you.

    That's a keeper.
    Last edited by stig.madsen; 2004-07-14 at 07:41 AM.

  8. #8
    Active Member
    Join Date
    2007-09
    Location
    Croatia
    Posts
    55
    Login to Give a bone
    0

    Default Re: vlax-curve-... functions

    Quote Originally Posted by stig.madsen View Post
    Hi David,
    I wrote a tiny "essay" on VLAX-CURVE functions here that might help you get started.

    If no one beats me to it I'll get back with a suggestion for the perp to object problem later.
    Hi!

    The URL does not work anymore,
    ????

  9. #9
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: vlax-curve-... functions

    Quote Originally Posted by marijan.marsic View Post
    Hi!

    The URL does not work anymore,
    ????
    Try this link, relaxed-curves.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  10. #10
    Active Member
    Join Date
    2007-09
    Location
    Croatia
    Posts
    55
    Login to Give a bone
    0

    Default Re: vlax-curve-... functions

    Quote Originally Posted by Opie View Post
    Try this link, relaxed-curves.

    Works!

    Pretty good essay,
    one thing steel unclear, the part;
    "VLAX-CURVE-GETCLOSESTPOINTTOPROJECTION, that projects a point onto the curve in a specific direction and returns the closest point, if any."

    Does it mean next:
    Projects the point and the curve in a given plane by normal vector on it, let us say (0,0,1)--horizontal plane, and then gives us a closestpoint on that projected curve (in this case horizontal planar curve, 2 dimenzional point )

    or :

    projects only point on that plane, and gives us closest point on "untouched" curve

    or:
    ????

    Thank You in advance!!

    Pozdrav iz Hrvatske

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 2012-11-24, 07:38 PM
  2. vlax-curve and UCS
    By irneb in forum AutoLISP
    Replies: 4
    Last Post: 2010-01-25, 01:02 PM
  3. Map VBA's VLAX ?
    By KevinBarnett in forum AutoCAD Map 3D - General
    Replies: 0
    Last Post: 2005-01-27, 09:00 AM
  4. Dwgprops, and vlax functions
    By JasonSelf in forum AutoLISP
    Replies: 1
    Last Post: 2004-09-04, 01:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •