Saturday, November 21, 2009
Home   |   Search   |   About AUGI   |   My AUGI   |   Join Now

Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP
 Welcome, Guest. 

Login

Join Now FAQ Members List Calendar Search Today's Posts Mark Forums Read

AutoLISP AutoLISP or Visual LISP, learn both here!

Reply
 
Thread Tools Display Modes
Old 2004-07-13, 01:07 PM   #1
David.Hoole
Active Member
 
David.Hoole's Avatar
 
Join Date: 2000-12
Location: Yorkshire
Posts: 81
David.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright future
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.
__________________
Regards,

David
David.Hoole is offline   Reply With Quote
Old 2004-07-13, 01:42 PM   #2
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
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.
stig.madsen is offline   Reply With Quote
Old 2004-07-13, 02:00 PM   #3
David.Hoole
Active Member
 
David.Hoole's Avatar
 
Join Date: 2000-12
Location: Yorkshire
Posts: 81
David.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright future
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.
__________________
Regards,

David
David.Hoole is offline   Reply With Quote
Old 2004-07-13, 03:41 PM   #4
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
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")
)
stig.madsen is offline   Reply With Quote
Old 2004-07-13, 04:06 PM   #5
David.Hoole
Active Member
 
David.Hoole's Avatar
 
Join Date: 2000-12
Location: Yorkshire
Posts: 81
David.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright future
Default RE: vlax-curve-... functions

Thanks Stig

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

David
David.Hoole is offline   Reply With Quote
Old 2004-07-14, 04:18 AM   #6
sinc
AUGI Addict
 
sinc's Avatar
 
Join Date: 2004-02
Location: Colorado
Posts: 1,531
sinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the stars
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 04:41 AM.
sinc is offline   Reply With Quote
Old 2004-07-14, 09:37 AM   #7
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
Default

Brilliant explanation, mr. Sincovec! Thank you.

That's a keeper.

Last edited by stig.madsen : 2004-07-14 at 09:41 AM.
stig.madsen is offline   Reply With Quote
Old 2004-07-15, 03:49 PM   #8
David.Hoole
Active Member
 
David.Hoole's Avatar
 
Join Date: 2000-12
Location: Yorkshire
Posts: 81
David.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright futureDavid.Hoole has a bright future
Default RE: vlax-curve-... functions

Thanks richards

Great explanation. Makes a complex subject seem almost simple.
__________________
Regards,

David
David.Hoole is offline   Reply With Quote
Old 2009-07-16, 10:57 AM   #9
marijan.marsic
Member
 
marijan.marsic's Avatar
 
Join Date: 2007-09
Location: CROATIA
Posts: 32
marijan.marsic has taken a wrong turn
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,
????
__________________
BANE
marijan.marsic is offline   Reply With Quote
Old 2009-07-16, 05:10 PM   #10
Opie
Programming Moderator
 
Opie's Avatar
 
Join Date: 2002-01
Location: jUSt Here (sometimes)
Posts: 5,483
Opie is celestialOpie is celestialOpie is celestialOpie is celestialOpie is celestialOpie is celestialOpie is celestialOpie is celestialOpie is celestialOpie is celestialOpie is celestial
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
Opie is offline   Reply With Quote
Reply


Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate curve table dipen1979 AutoLISP 5 2004-07-12 08:10 PM
callin functions between class modules inner VBA 4 2004-07-11 01:48 AM
Calculate a curve? smiller AutoLISP 4 2004-06-22 02:57 PM
Exceeded iteration limit when evaluating curve earld AutoCAD 3D (2006 or below) 2 2004-06-03 04:30 PM
Anyone know how to cut out a flat plate and then curve it? Darrel Odom Revit Architecture - General 16 2004-04-15 02:00 PM


All times are GMT +1. The time now is 04:28 PM.