 # Generate an Epitrochoidal Spline Curve (AutoLISP Solutions AutoCAD Tutorial)

31 Dec, 2007

### This solution draws a spline of an epitrochoid in AutoCAD to simplify the process of developing machined parts.

Don Barnett of Arizona e-mailed a request to draw a spline of an epitrochoid so he can develop a machined part from it. Barnett provided the mathematical representation of the curve in AutoLISP form. The parametric equations for an epitrochoid are shown in the figure below.

An epitrochoid is a roulette traced by a point attached to a circle of radius r rolling around the outside of a fixed circle of radius R, where the point is a distance d from the center of the exterior circle.

The parametric equations for an epitrochoid are The AutoLISP Solution uses SPLINECURVE.LSP and SPLINECURVE.DCL. The routine automatically draws an epitrochoidal spline using input from a user for the base circle radius, rolling circle radius, eccentricity, and resolution.

Get the Code!

How to Use the SPLINECURVE.LSP Code
To start the program, enter S1 on the Command line, and you will see the Epitrochoidal spline data dialog box as shown below. The Epitrochoidal spline data dialog box.

You can select the base circle radius, rolling circle radius, and eccentricity from the dialog box as shown above. The resolution controls the radian increment of the spline control points.

The default resolution setting near the low end of the slider produces an accuracy as shown in the results of the figure below and draws the spline curve in approximately 1 second. Producing the maximum resolution takes a long time to draw the spline. (As we used to say in the early days of CAD, "Time to take a coffee break!") The rolling circle radius must be one-half that of the base circle radius to produce the symmetrical shape shown below. When the parameters have been set, simply click the OK button to draw the epitrochoidal spline. A typical result of an epitrochoidal spline.

Programming Notes
After running my usual error and system-variable management functions, the dialog box driver function 1Spline initializes the spline data, draws the spline image, and calls the Do-Spline function. The spline image in the dialog box is calculated by the Draw-Spline-Image function, which I prefer to using a slide image simply to reduce the number of source files involved the program. This calculation in turn uses functions for drawing arcs and vectors that I had previously written, so the effort of writing the dialog box image function isn't very time-consuming.

Do-Spline uses the parametric equations shown in the first figure, and much of this code was supplied by Don Barnett. The code is as follows:

`(setq Tn 0)  (setq ptlst nil)  (setq Tninc (/ (* pi 2) resolution))  (repeat resolution    (setq A1 (cos Tn))    (setq X1 (* (+ R1 R2) A1))    (setq A2 (/ (* (+ R1 R2) Tn) R2))    (setq X2 (* (cos A2) H))    (setq X (- X1 X2))    (setq B1 (sin Tn))    (setq Y1 (* (+ R1 R2) B1))    (setq B2 (/ (* (+ R1 R2) Tn) R2))    (setq Y2 (* (sin B2) H))    (setq Y (- Y1 Y2))    (setq pt2 (list X Y 0.0))    (setq ptlst (append ptlst pt2))    (setq Tn (+ Tninc Tn))  ) ;_ end of repeat`

This code segment produces a list of points suitable for drawing the spline with a call to Make-Spline that uses the standard AddSpline method as follows:

`(setq	ptanx	  (nth 0 plst)    ptany	  (nth 1 plst)    ptanz	  (nth 2 plst)    ptan	  (vlax-3D-point ptanx ptany ptanz)    ptanstart (vla-PolarPoint *utility* ptan (* pi 0.5) 10.0)    ptanend   (vla-PolarPoint *utility* ptan (* pi 1.5) 10.0)  ) ;_ end of setq  (setq arr (vlax-make-safearray 5 (cons 0 (- (length plst) 1))))  (vlax-safearray-fill arr plst)  (setq	spline (vla-AddSpline        *modelspace*        (vlax-make-variant arr)        ptanstart        ptanend        ) ;_ end of vla-AddSpline  ) ;_ end of setq`

As always, I look forward to receiving your comments and requests for future "AutoLISP Solutions" columns. Contact me using the links below.