|
Welcome, Guest.
|
||||||
| AutoLISP AutoLISP or Visual LISP, learn both here! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Active Member
Join Date: 2000-12
Location: Yorkshire
Posts: 81
![]() ![]() ![]() ![]() ![]() ![]() |
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 |
|
|
|
|
|
#3 |
|
Active Member
Join Date: 2000-12
Location: Yorkshire
Posts: 81
![]() ![]() ![]() ![]() ![]() ![]() |
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 |
|
|
|
|
|
#4 | |
|
100 Club
Join Date: 2000-12
Posts: 126
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Thanks David.
Quote:
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 |
|
Active Member
Join Date: 2000-12
Location: Yorkshire
Posts: 81
![]() ![]() ![]() ![]() ![]() ![]() |
Thanks Stig
Exactly what I needed. I'll make good use of this lesson!
__________________
Regards, David |
|
|
|
|
|
#6 |
|
AUGI Addict
Join Date: 2004-02
Location: Colorado
Posts: 1,531
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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. |
|
|
|
|
|
#7 |
|
100 Club
Join Date: 2000-12
Posts: 126
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Brilliant explanation, mr. Sincovec! Thank you.
That's a keeper. Last edited by stig.madsen : 2004-07-14 at 09:41 AM. |
|
|
|
|
|
#8 |
|
Active Member
Join Date: 2000-12
Location: Yorkshire
Posts: 81
![]() ![]() ![]() ![]() ![]() ![]() |
Thanks richards
Great explanation. Makes a complex subject seem almost simple.
__________________
Regards, David |
|
|
|
|
|
#9 | |
|
Member
Join Date: 2007-09
Location: CROATIA
Posts: 32
![]() |
Quote:
The URL does not work anymore, ????
__________________
BANE |
|
|
|
|
|
|
#10 |
|
Programming Moderator
Join Date: 2002-01
Location: jUSt Here (sometimes)
Posts: 5,483
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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
|
|
|
|
![]() |
|
||||||
| Thread Tools | |
| Display Modes | |
|
|
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 |