
Generate an Epitrochoidal Spline Curve (AutoLISP Solutions AutoCAD Tutorial)
1 Jan, 2008 By: Tony HotchkissThis solution draws a spline of an epitrochoid in AutoCAD to simplify the process of developing machined parts.
Don Barnett of Arizona emailed 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!
Download the SPLINECURVE.LSP and SPLINECURVE.DCL files from Cadalyst's CAD Tips site. Save the file in AutoCAD's Support directory. Use the Appload facility by selecting Tools / Load Application, and then use the browser to select the file.
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 onehalf 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 systemvariable management functions, the dialog box driver function 1Spline initializes the spline data, draws the spline image, and calls the DoSpline function. The spline image in the dialog box is calculated by the DrawSplineImage 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 timeconsuming.
DoSpline 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 MakeSpline that uses the standard AddSpline method as follows:
(setq ptanx (nth 0 plst)
ptany (nth 1 plst)
ptanz (nth 2 plst)
ptan (vlax3Dpoint ptanx ptany ptanz)
ptanstart (vlaPolarPoint *utility* ptan (* pi 0.5) 10.0)
ptanend (vlaPolarPoint *utility* ptan (* pi 1.5) 10.0)
) ;_ end of setq
(setq arr (vlaxmakesafearray 5 (cons 0 ( (length plst) 1))))
(vlaxsafearrayfill arr plst)
(setq spline (vlaAddSpline
*modelspace*
(vlaxmakevariant arr)
ptanstart
ptanend
) ;_ end of vlaAddSpline
) ;_ 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.

AutoCAD Tips!
Autodesk Technical Evangelist Lynn Allen guides you through a different AutoCAD feature in every edition of her popular "Circles and Lines" tutorial series. For even more AutoCAD howto, check out Lynn's quick tips in the Cadalyst Video Gallery. Subscribe to Cadalyst's free Tips & Tools Weekly enewsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst! 
