Gathering Information
Before a problem can be solved, you must first gather all the known factors affecting the problem. The program you will explore next
will give an example of how you might go about your information gathering.
Exit AutoCAD and open an AutoLISP file called Cutcr.lsp. Carefully copy the program in figure 6.10 into this file. Save and exit the
Cutcr.lsp file then start AutoCAD and open the Chapt6 file again. Load the Ctcr.lsp fine then do the following:
1. Erase everything on the screen then draw a circle with its center at point 8,6 and a with a radius of 3 units
(see figure 6.11).
2. Enter cutcr at the command prompt to start the C:CUTCR program.
3 At the prompt:
Pick circle to cut:
pick the circle you just drew.
4. At the next prompt:
Pick first point of cut line:
pick a point at coordinate 5,9.
5. At the prompt:
Pick second point:
pick a point at coordinate 8,2.
The circle is cut into two arcs along the axis represented by the two points you picked (see figure6.12).
6. Use the erase command to erase the left half of the circle. You can now see that the circle has been cut
(see figure 6.13).
;Program to cut a circle into two arcs -- Cutcr.lsp
(defun C:CUTCR (/ cpt1 lpt1 lpt2 cent rad1 ang1 dst1 dst2 cord ang2 wkpt cpt2 cpt3)
(setvar "osmode" 512) ;osnap to nearest
(setq cpt1 (getpoint "\nPick circle to cut: ")) ;find point on circle
(setvar "osmode" 0) ;osnap to none
(setq lpt1 (getpoint "\nPick first point of cut line: ")) ;1st point of cut
(setq lpt2 (getpoint lpt1 "\nPick second point: ")) ;2nd point of cut
(setq cent (osnap cpt1 "center")) ;find center pt
(setq rad1 (distance cpt1 cent)) ;find radius of circle
(setq ang1 (- (angle lpt1 cent)(angle lpt1 lpt2))) ;find difference of angles
(setq dst1 (distance lpt1 cent)) ;find dist.lpt1 to cent
(setq dst2 (* dst1 (sin ang1))) ;find side of triangle
(setq cord (sqrt(-(* rad1 rad1)(* dst2 dst2)))) ;find half cord
(setq ang2 (- (angle lpt1 lpt2) 1.57)) ;find perpend angle
(setq wkpt (polar cent ang2 dst2)) ;find workpoint
(setq cpt2 (polar wkpt (angle lpt1 lpt2) cord)) ;find first intersect
(setq cpt3 (polar wkpt (angle lpt2 lpt1) cord)) ;find second intersect
(command "erase" cpt1 "" ;erase circle
"arc" "c" cent cpt2 cpt3 ;draw first circle seg.
"arc" "c" cent cpt3 cpt2 ;draw second circle seg.
) ;close command funct.
) ;close defun
Figure 6.10: The circle cut program
Figure 6.11: The circle drawn in AutoCAD
Figure 6.12: Drawing the cut axis.
Figure 6.13: Erasing one part of the circle after it has been cut.
The first three expressions in the program after the defun functions and its arguments obtain a point on the circle:
(setvar "osmode" 512)
(setq cpt1 (getpoint "\nPick circle to cut: "))
(setvar "osmode" 0)
The setvar function sets osnap to the nearest mode then the user is prompted to pick the circle to cut. This point is stored as cpt1. The
osnap mode ensures that the point picked is exactly on the circle. Later, this point will be used to both erase the circle and to find the
circles center. The next function sets osnap back to none.
The next two lines prompt the user to select the points that define the axis along which the circle is to be cut:
(setq lpt1 (getpoint "\npick first point of cut line: "))
(setq lpt2 (getpoint lpt1 "\nPick second point: "))
The getpoint function is used in both these expressions to obtain the endpoints of the cut axis. These endpoints are stored as lpt1 and
lpt2.
The next expression uses a new function called osnap:
(setq cent (osnap cpt1 "center"))
Here the point picked previously as the point on the circle cpt1 is used in conjunction with the osnap function to obtain the center point
of the circle. The syntax for osnap is:
(osnap [point value][osnap mode])
The osnap function acts in the same way as the osnap overrides. If you use the center osnap override and pick a point on the circle, you
get the center of the circle. Likewise, the osnap function takes a point value and applies an osnap mode to it to obtain a point. In this
case, osnap applies the center override to the point cpt1 which is located on the circle. This gives us the center of the circle which is
assigned to the symbol cent.
The next expression obtains the circle's radius
(setq rad1 (distance cpt1 cent))
The distance function is used to get the distance from cpt1, the point located on the circle, to cent, the center of the circle. This value is
assigned to the symbol rad1.
Next -> Finding Points Using Trigonometry