Current location - Recipe Complete Network - Complete cookbook of home-style dishes - How to draw sine curve with CAD
How to draw sine curve with CAD
Open CAD, click Tools →AutoLISP→Visual LISP Editor, create a new file, and enter the following code:

(defun C:draw sin(/left point left pointx left pointy N x step)(init get 1); 1 to 8-bit binary is 000000 1, and setting 0-bit to 1 means that users are prohibited from pressing Enter to respond to input requests.

(setq left point(getpoint " \ n left point:")left pointx(car left point)left pointy(cadr left point))(init get 7); The 7-to 8-bit binary is 0000011. Setting bit 1 to 1 means that the user is prohibited from entering a zero value to respond to the input request, and setting bit 2 to 1 means that the user is prohibited from entering a negative value to respond to the input request.

(setq n (getint "\ n cycles number:")) (setq x0step0.1) (command "pline") (while (<: x(* 2nπ))

(command(list(+left pointx x)(+left pointy(sin x))); Draw a sine curve (setq x(+x step));) point by point with LeftPoint as the origin; X = x+ step, and the abscissa increases the step value)

(command(list(+left pointx x)(+left pointy(sin x)))(list(+left pointx(* 2n pi))left pointy)" ")

(command "line" leftpoint (list (+leftpointx (* 2npi)) leftpointy) "); Draw the X axis (command "line" (list leftpointx (+leftpointy2)) ""); Draw the y axis)

Save it as a drawsine.lsp file, and press Ctrl+Alt+E, and the Visual LISP console will display something similar to: "; 1 table from # autocad2004/sample/visuallisp/drawsine.lsp ">; Load "text, the focus automatically switches to the Visual LISP console. Enter (C:drawsin) or draw in command in CAD to run this function. If there is no "c:" in the function definition, it can only be called in the Visual LISP console. After the function runs, use the mouse to specify the coordinate origin in the active window of CAD, and then enter the number of cycles of the sine curve to be drawn in the console to draw this curve.

I changed a buggy program in a tutorial, and this is it. I wrote my own Chinese notes and operation steps. I think this program is very typical and useful, because you can use other functions instead of sin(x) to draw their images.