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.

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.

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")

)

RE: vlax-curve-... functions

Thanks Stig

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

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.)

RE: vlax-curve-... functions

Thanks richards

Great explanation. Makes a complex subject seem almost simple.

Re: vlax-curve-... functions

Quote:

Originally Posted by

**stig.madsen**
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,

????

Re: vlax-curve-... functions

Quote:

Originally Posted by

**marijan.marsic**
Hi!

The URL does not work anymore,

????

Try this link, relaxed-curves.