
Here there are no negative signs to turn the world upside down. (setq polyobj (make-LWpolyline plist)) polyline object
#Drawing sine waves in autocad code#
This has always struck me as a particularly silly decision that was clearly made by a graphically challenged mathematician with a matrix fetish.Ĭompare the above code to that of the main Sinecurve function that collects the points necessary to draw the polyline in the following fragment:

The x- and y-origin of image tiles is at the top left instead of at the lower left. This is possible because the function DO-VECTOR converts the points to the x- and y-integer values required by the AutoLISP VECTOR_IMAGE function.Ī small inconvenience in drawing image tiles is caused by the reversed positive direction of the y-axis. The code is written using the points p1 and p2, much the way that would be used to program lines between two points on the regular AutoCAD screen. (setq y (- y0 (* A (sin (/ (* 2 pi (setq x (+ x xinc))) xmax))))įor this function, I set the number of points NP at 144, which gives a very smooth-looking image, as shown in figure 1. The code to draw the sine curve takes a number of definition points NP, and runs a repeat loop as follows: I have previously written functions to draw lines (vectors), arcs and circles in image tiles for dialog boxes, and in this case only the vector is required. Even if the LISP program is compiled, it is not possible to include slide libraries in the compiled set of data. I favor this method of creating images over using slides because there are fewer files to keep track of. Immediately following INIT-SINE, the DRAW-SINE-IMAGE function is called to create the image of a sine curve. If the program has already been run in the current session of AutoCAD, then all the dialog box data values are reused as new defaults because the period, amplitude, number of cycles and resolution are stored in global variables.
#Drawing sine waves in autocad driver#
The function SINE is the dialog box driver function that calls INIT-SINE to initialize the settings in the dialog box. SINECURVE.LSP starts as usual with my error handler and system variable functions. The program was written in AutoCAD 2004, and has been tested in both AutoCAD 20, but it should work in any version of AutoCAD later than 2000. The spline would always result in a curve that is smaller in amplitude than the polyline because the spline curve lies on the concave side of its control points. It's possible to convert the polyline to a spline curve, but that would not be as accurate as the fit curve because splines do not pass through their control points. After you enter SC, the Sine Curve dialog box pops up as shown (figure 1).įigure 2. To see this prompt, you may need to set your Command window size to 3 lines by dragging the Command window splitter bar appropriately. Use the Appload facility by selecting Tools / Load Application, and then use the browser to select the file.Īfter you load the code, the system prompts you to enter SC to start the program. Save the file in AutoCAD's Support directory. The routine allows the user to select the periodic time (equivalent to the pitch of a thread), the amplitude (half the height for a thread), the number of cycles to display and the resolution or display accuracy of the curve.ĭownload the SINECURVE.LSP and SINECURVE.DCL files from Cadalyst's CAD Tips site. The AutoLISP Solution is SINECURVE.LSP, and the corresponding dialog box file SINECURVE.DCL. Normally this is quite time-consuming because it requires tracing a curve through many points that must be calculated or constructed. This type of curve occurs in many situations, including a two-dimensional helix and screw threads. Ralph wants to draw a sinusoidal curve as a spline or polyline. This month's request came from Ralph Ragan of Atlanta, Georgia.

AutoLISP Solutions: Draw a Sinusoidal Curve as a Spline or Polyline 14 Mar, 2005 By: Tony Hotchkiss Cadalyst Bypass the process of tracing a curve through many points that must be calculated or constructed
