Part Three - SpiralI added some new lines of code to the spiral program to correct the
start and end tangency points of the spiral. You should view the updated
version:-
Analyze CodePortions of the column showing code that was used in the earlier version of the spiral program code will be in red. New Variables and Calculations... (setq #ANGLE-TAN (/ pi 500)) (setq #Z-TAN (/ #PITCH 1000)) (setq #TAN-0 (polar #POINT-0 (- #ANGLE-TAN) #RADIUS)) (setq #TAN-0 (list (car #TAN-0) (cadr #TAN-0) (- (caddr #TAN-0) #Z-TAN))) (setq #Z-END (caddr (last #LIST))) (setq #TAN-1 (polar #POINT-0 #ANGLE-TAN #RADIUS)) (setq #TAN-1 (list (car #TAN-1) (cadr #TAN-1) (+ #Z-END #Z-TAN))) ... The AutoCAD spline command asks for tangency directions for the start and endpoints of splines. In the earlier version of SPIRAL, we used the defaults rather than calculate the correct tangency values. I used a value of 16 for the resolution, which is high enough to give a fairly accurate spiral. At much higher resolution values, the default tangency points would actually be fairly good. But speed of the spiral program would needlessly suffer. So we will use a high resolution of 1/1000th of a circle to calculate just the start and end tangency points. You could use 1/100 or 1/10000. But 1/1000 is good enough. All other points will remain at a resolution of 1/16th of a circle.
Use of New Tangency Points in Spline... (command "" "" "") ... ... (command "" #TAN-0 #TAN-1) ... I replaced the above line shown in red from
Make Variables Local(defun C:SPIRAL (/ #DIAMETER #PITCH) ... (defun C:SPIRAL (/ #ANGLE #ANGLE-DELTA #ANGLE-TAN #COILS #DIAMETER #LIST #PITCH #POINT #POINT-0 #POINT-1 #RADIUS #RESOLUTION #SEGMENTS #TAN-0 #TAN-1 #Z #Z-DELTA #Z-END #Z-TAN) ... In Part Two, I left most of the variable names out of the "local" variable list. Leaving the variables global can help in debugging but I decided now would be a good time to start cleaning things up a bit. ... (setq #LIST nil) ... Since the #LIST variable is now local it gets reset to nil inside the program whenever it is executed. So I no longer need the above line that explicitly set it to nil. So this line is no longer included in the spiral program. You can draw spirals using the same input applied to
Part Four will detail the modifications needed to insure correct user input and make the program easier to use.
|