Вы находитесь на странице: 1из 42

1. Input the length of sides of triangle and check whether it forms a triangle or not.

if it forms a triangle draw the triangle. PROGRAM 1 ( defun c:PROG1() (setq s1 (getreal "Enter length of 1st side: ")) (setq s2 (getreal "Enter length of 2nd side: ")) (setq s3 (getreal "Enter length of 3rd side: ")) (cond ;For sorting given sides in ascending order ( (> s1 s2) (setq temp1 s2) (setq s2 s1) (setq s1 temp1) ) ( (> s2 s3) (setq temp2 s3) (setq s3 s2) (setq s2 temp2) ) ( (> s1 s2) (setq temp3 s2) (setq s2 s1) (setq s1 temp3) ) ) (cond ( (> (+ s1 s2) s3) ;For checking condition for triangle (setq pt1 (getpoint "Enter insertion point of triangle: ")) (setq pt2 (list (+ (car pt1) s1) (cadr pt1))) (setq x (/ (+ (* s1 s1) (- (* s2 s2) (* s3 s3))) (* 2 s1)));x=(a^2 + b^2 - c^2)/(2a) (setq z (- (* s2 s2) (* x x))) ;y=sqrt(b^2 - x^2) (setq y (sqrt z)) (setq pt3 (list (+ (car pt1) x) (+ (cadr pt1) y))) (command "line" pt1 pt2 pt3 pt1 "") ) ( (<= (+ s1 s2) s3) (princ "These sides do not form a triangle") ) ) )

****************OUTPUT****************** Command: PROG1 Enter length of 1st side: 5 Enter length of 2nd side: 3 Enter length of 3rd side: 7 Enter insertion point of triangle:

2.Input the diameter of flange. According to diameter of the flange create no of holes on the flange. PROGRAM 2 ( defun c:PROG2() (setq c1 (getpoint "Select center of flange: ")) (setq dia (getreal "Enter diameter of flange: ")) (setq pcd (getreal "Enter p.c.d: ")) (setq c2 (list (car c1) (+ (cadr c1) (/ pcd 2)))) (setq rhole (getreal "Enter hole radius :")) (setq n (getint "Enter no.of holes :")) (command "circle" c1 (/ dia 2)) (command "circle" c2 rhole) (command "array" "l" "" "p" c1 n "360" "n") (setq pt1 (list (- (car c1) (* dia 0.8)) (cadr c1))) (setq pt2 (list (+ (car c1) (* dia 0.8)) (cadr c1))) (command "line" pt1 pt2 "" ) (setq pt3 (list (car c1) (- (cadr c1) (* dia 0.8)))) (setq pt4 (list (car c1) (+ (cadr c1) (* dia 0.8)))) (command "line" pt3 pt4 "" ) ) ******************OUTPUT****************** Command: PROG2 Select center of flange: Enter diameter of flange: 20 Enter p.c.d: 12 Enter hole radius :0.5 Enter no.of holes :8

Input the end points of diagonal of the quadrilateral. Find out where it is square or rectangle. If it is a square or rectangle then draw the same. Assume base of quadrilateral is parallel to x-axis.

PROGRAM 3 ( defun c:PROG3() (setq pt1 (getpoint "Enter one endpoint of diagonal of quadrilateral: ")) (setq pt3 (getpoint "Enter other endpoint of diagonal of quadrilateral: ")) (setq pt2 (list (car pt3) (cadr pt1))) (setq pt4 (list (car pt1) (cadr pt3))) (setq x1 (- (car pt3) (car pt1))) (setq x (abs x1)) (setq y1 (- (cadr pt3) (cadr pt1))) (setq y (abs y1)) (command "line" pt1 pt2 pt3 pt4 pt1 "") (cond ( (= x y) (princ "Quadrilateral is square") ) ( (/= x y) (princ "Quadrilateral is rectangle") ) ) (princ) ) ***************OUTPUT***************** Command: PROG3 Enter one endpoint of diagonal of quadrilateral: Enter other endpoint of diagonal of quadrilateral: Quadrilateral is rectangle

4 Input the length of sides of triangle and find out which type of triangle it is and draw the same. PROGRAM 4 ( defun c:PROG4() (setq s1 (getreal "Enter length of 1st side: ")) (setq s2 (getreal "Enter length of 2nd side: ")) (setq s3 (getreal "Enter length of 3rd side: ")) (if (> s1 s2) ;For sorting given sides in ascending order (progn (setq temp1 s2) (setq s2 s1) (setq s1 temp1) ) () ) (if (> s2 s3) (progn (setq temp2 s3) (setq s3 s2) (setq s2 temp2) ) () ) (if (> s1 s2) (progn (setq temp3 s2) (setq s2 s1) (setq s1 temp3) ) () ) (cond ( (> (+ s1 s2) s3) (setq pt1 (getpoint "Enter insertion point of triangle: ")) (setq pt2 (list (+ (car pt1) s1) (cadr pt1))) (setq x (/ (+ (* s1 s1) (- (* s2 s2) (* s3 s3))) (* 2 s1))) (setq z (- (* s2 s2) (* x x))) (setq y (sqrt z)) (setq pt3 (list (+ (car pt1) x) (+ (cadr pt1) y))) (command "line" pt1 pt2 pt3 pt1 "") (cond ( (and (= s1 s2) (= s2 s3)) ;Condition for equilateral (princ "Triangle is equilateral") ) ( (or (= s1 s2) (= s2 s3) (= s1 s3)) ;Condition for isosceles (princ "Triangle is isosceles") ) (princ "Triangle is scalene") )

) ( (<= (+ s1 s2) s3) (princ "These sides do not form a triangle") ) ) ) *******************OUTPUT******************* C:PROG4 Command: PROG4 Enter length of 1st side: 5 Enter length of 2nd side: 3 Enter length of 3rd side: 7 Enter insertion point of triangle: Triangle is scalene

Draw a circle and pick a point on the screen. Find out whether the point lies inside or outside the circle.

PROGRAM 5 ( defun c:PROG5() (setq c (getpoint "Select center of circle: ")) (setq r (getreal "Enter radius of circle: ")) (command "circle" c r) (setq pt1 (getpoint "Select any point on the screen: ")) (setq x (- (car pt1) (car c))) (setq y (- (cadr pt1) (cadr c))) (setq z (+ (* x x) (* y y))) (setq dis (sqrt z)) (cond ( (> dis r) (princ "Point selected lies outside circle") ) ( (< dis r) (princ "Point selected lies inside circle") ) ( (= dis r) (princ "Point lies on circle") ) ) ) ******************OUTPUT******************** C:PROG5 Command: PROG5 Select center of circle: Enter radius of circle: 5 Select any point on the screen: Point selected lies outside circle

Select a geometrical entity (line/circle). If it is line find the length angle of line. If it is a circle find radius and center points coordinate.

PROGRAM 6 ( defun c:PROG6() (setq a (entget (car (entsel "Select object: ")))) (cond ( (= (cdr (assoc 0 a)) "LINE") (setq pt1 (cdr (assoc 10 a))) (setq pt2 (cdr (assoc 11 a))) (princ "End coordinates are ") (princ pt1) (princ pt2) (setq len (distance pt1 pt2)) (princ "Length of line is ") (princ len) ) ( (= (cdr (assoc 0 a)) "CIRCLE") (setq c (cdr (assoc 10 a))) (princ "Center of circle is ") (princ c) (setq r (cdr (assoc 40 a))) (princ "Radius of circle is ") (princ r) ) ) (princ) ) *************OUTPUT*************************** C:PROG6 Command: PROG6 Select object: Center of circle is (25.3331 13.5295 0.0) Radius of circle is 6.15538

Draw a circle. Select option for hatching (1/2). If it is 1, draw hatch using select object option and if it is 2, then draw the hatch with pick point option.

PROGRAM 7 ( defun c:PROG7() (setq c (getpoint "Select center of circle: ")) (setq r (getreal "Enter radius of circle: ")) (command "circle" c r) (setq opt (getint "Select option for hatching 1 or 2 : ")) (if (= opt 1) (progn (command "bhatch" "select") (setq a (entsel "Select object to hatch: ")) (command a "" "") ) (progn (command "bhatch" "internal" "") (setq b (getpoint "Select internal point for hatching: ")) (command b "") ) ) ) ************OUTPUT******************** Command: PROG7 Select center of circle: Enter radius of circle: 5 Select option for hatching 1 or 2 : 1

Draw an arc. Find out the included angle of the arc. Depending upon the angle, decide the no of division of the arc and divide the arc.

PROGRAM 8 ( defun c:PROG8() (setq c1 (getpoint "Select center of arc: ")) (setq pt1 (getpoint "Select start point of arc: ")) (setq pt2 (getpoint "Select end point of arc: ")) (command "arc" "c" c1 pt1 pt2) (setq ang (angle c1 pt1)) (princ "Included angle is ") (princ ang) (princ) (setq r (distance c1 pt1)) (setq angd (/ ang 5)) (setq i 1) (setq ang1 angd) (command "line" c1 pt1 "") ( while (<= i 6) (setq pt1 (polar c1 ang1 r)) (command "line" c1 pt1 "") (setq ang1 (+ ang1 angd)) (setq i (+ i 1)) ) (command "line" c1 pt2 "") ) *******************OUTPUT***************************

Draw square and circle (inscribe of circumscribe). Find out who is what according to dimension.

circumscribing

PROGRAM 9 ( defun c:PROG9() (setq a (entget (car (entsel "Select circle: ")))) (setq c (cdr (assoc 10 a))) (setq r (cdr (assoc 40 a))) (setq a (entget (car (entsel "Select square: ")))) (setq pt1 (cdr (assoc 10 a))) (setq dis (distance pt1 c)) (if (= dis r) (princ "Circle is circumscribing square ") (princ "Circle is inscribed in square ") ) (princ) ) ******************OUTPUT********************* Command: PROG9 Select circle: Select square: Circle is circumscribing square Command: PROG9 Select circle: Select square: Circle is inscribed in square

10 Draw a line and pick a point on the line with mouse. Find out whether that point lie left or right of the midpoint of the line. PROGRAM 10 ( defun c:PROG10() (setq pt1 (getpoint "Select starting point of line: ")) (setq pt2 (getpoint "Select endpoint of line: ")) (command "line" pt1 pt2 "") (setq pt3 (getpoint "Select a point on the line: ")) (setq x (- (car pt2) (car pt1))) (setq y (- (cadr pt2) (cadr pt1))) (setq mid (list (+ (car pt1) (/ x 2)) (+ (cadr pt1) (/ y 2)))) (setq a (- (car mid) (car pt1))) (setq b (- (cadr mid) (cadr pt1))) (setq dismid (sqrt (+ (* a a) (* b b)))) ;Distance of midpt w.r.t 1st point (setq c (- (car pt3) (car pt1))) (setq d (- (cadr pt3) (cadr pt1))) (setq dispt3 (sqrt (+ (* c c) (* d d)))) ;Distance of selected pt w.r.t 1st point (cond ( (> dismid dispt3) (princ "Selected point is to the left of midpoint of line") ) ( (< dismid dispt3) (princ "Selected point is to the right of midpoint of line") ) ( (= dismid dispt3) (princ "You have selected the midpoint") ) ) ) *****************OUTPUT************************ Command: PROG10 Select starting point of line: Select endpoint of line: Select a point on the line: Selected point is to the right of midpoint of line

11 Find the summation of series like: Sum=x+x^2+x^3+x^4+.. PROGRAM 11 ( defun c:PROG11_2() (setq x (getint "Enter series variable: ")) (setq n (getint "Enter length of series: ")) (setq i 1) (setq sum 0) ( while (<= i n) (setq sum1 (* (expt (- 0 1) (+ i 1)) (expt x i))) (setq sum (+ sum sum1)) (setq i (+ i 1)) ) (princ "Sum is ") (princ sum) (princ) ) *************OUTPUT************************* C:PROG11_2 Command: PROG11_2 Enter series variable: 2 Enter length of series: 4 Sum is -10

12 Input number of forces and find the resultant (magnitude and direction). the force polygon. PROGRAM 12 ( defun c:PROG12() (setq pt1 (getpoint "Enter start point: ")) (setq n (getreal "Enter no. of forces: ")) (setq a pt1) (setq i 1) (command "pline" pt1) ( while (<= i n) (setq mag (getreal "Enter magnitude of force: ")) (setq ang (getreal "Enter angle of force: ")) (setq pt2 (polar pt1 (* (/ pi 180) ang) mag)) (command pt2) (setq pt1 pt2) (setq i (+ i 1)) ) (command a "") (setq mag1 (distance a pt2)) (setq ang1 (angle a pt2)) (prompt "Magnitude = ") (princ mag1) (prompt "Angle = ") (princ ang1) (princ) ) *****************OUTPUT****************** Command: PROG12 Enter start point: Enter no. of forces: 2 Enter magnitude of force: 30 Enter angle of force: 45 Enter magnitude of force: 30 Enter angle of force: 120 Magnitude = 47.6012 Angle = 1.4399

Draw

13 Input the number of sides and draw polygon. (create polygon command) PROGRAM 13 ( defun c:PROG13() (setq pt1 (getpoint "Enter start point: ")) (setq n (getint "Enter no. of sides: ")) (setq l (getreal "Enter length of sides: ")) (setq angv (/ 360 n)) (setq ang 0) (setq i 1) (setq a pt1) (command "pline" pt1 ) ( while (<= i n) (setq pt2 (polar pt1 (* ang (/ pi 180)) l)) (command pt2) (setq ang (+ ang angv)) (setq pt1 pt2) (setq i (+ i 1)) ) (command a "") ) *********************OUTPUT*********************** C:PROG13 Command: PROG13 Enter start point: Enter no. of sides: 5 Enter length of sides: 10

14 Create polar array command for circle. PROGRAM 14 ( defun c:PROG14_2() (setq c1 (getpoint "Select center of circle: ")) (setq r (getreal "Enter radius of circle: ")) (setq pt1 (polar c1 (/ (* pi 3) 2) r)) (command "point" pt1) (command "array" "l" "" "p" c1 "720" "" "n") ) ******************OUTPUT****************** Command: PROG14_2 Select center of circle: Enter radius of circle: 5

15 circle. Create rectangular array command for PROGRAM 15 ( defun c:PROG15() (setq a (entget (car (entsel "Select circle: ")))) (setq c (cdr (assoc 10 a))) (setq r (cdr (assoc 40 a))) (setq nr (getint "Enter no. of rows: ")) (setq nc (getint "Enter no. of columns: ")) (setq dr (getreal "Enter distance between rows: ")) (setq dc (getreal "Enter distance between columns: ")) (setq i 1) (setq c1 (list (car c) (cadr c))) ( while (<= i nc) (setq j 1) ( while (< j nr) (setq x (* j dc)) (setq c2 (list (car c1) (+ (cadr c1) x))) (command "circle" c2 r) (setq j (+ j 1)) ) (command "circle" c1 r) (setq c1 (list (+ (car c1) dc) (cadr c1))) (setq i (+ i 1)) ) (princ) ) *********************OUTPUT************************** C:PROG15 Command: PROG15 Select circle: Enter no. of rows: 3 Enter no. of columns: 5 Enter distance between rows: 10 Enter distance between columns: 15

16 Create multiple copy command for circle. PROGRAM 16 ( defun c:PROG16() (setq a (entget (car (entsel "Select circle: ")))) (setq c (cdr (assoc 10 a))) (setq r (cdr (assoc 40 a))) (setq ans y) ( while (/= ans "n") (setq c2 (getpoint "\nSelect center for circle to move: ")) (command "circle" c2 r) (setq ans (getstring "Do you want to continue: y / n : ")) ) (princ) ) *************************OUTPUT********************** Command: PROG16 Select circle: Select center for circle to move: Do you want to continue: y / n : y Select center for circle to move Do you want to continue: y / n : n

17 Draw f(x) curve for given limits. PROGRAM 17 ( defun c:PROG17() (setq x (getreal "Enter a number: ")) (setq a (list x (* 4 x))) (command "pline" a) ( while (>= x 0.1) (setq a (list x (* 4 x))) (command a) (setq x (- x 0.1)) ) (command "") ) *********************OUTPUT******************** C:PROG17 Command: PROG17 Enter a number: 6

18 Creating bill of material. PROGRAM 18 ( defun c:PROG18() (setq pt1 (getpoint "Select insertion point: ")) ;1st heading (setq pt2 (polar pt1 0 30)) ;2nd heading (setq pt3 (polar pt1 0 60)) ;3rd heading (setq pt4 (polar pt1 0 90)) ;4th heading (setq pt5 (polar pt1 0 120)) ;5th heading (setq pt6 (polar pt5 0 30)) ;Line end for row of box (setq pt7 (polar pt1 (/ pi 2) 100)) ;Line start for column of box (command "text" (polar pt1 (/ pi 4) 8) 2.5 0 "Part No." "" "") ;Polar command for spacing from border of box (command "text" (polar pt2 (/ pi 4) 8) 2.5 0 "Description." "" "") (command "text" (polar pt3 (/ pi 4) 8) 2.5 0 "Material." "" "") (command "text" (polar pt4 (/ pi 4) 8) 2.5 0 "Qty." "" "") (command "text" (polar pt5 (/ pi 4) 8) 2.5 0 "Remarks." "" "") (command "line" pt1 pt6 "") (command "array" "l" "" "r" 9 1 12.5) (command "line" pt1 pt7 "") (command "array" "l" "" "r" 1 6 30) ) *******************OUTPUT************************ C:PROG18 Command: PROG18 Select insertion point:

19 Create move command if the object is selected with entsel.

PROGRAM 19 ( defun c:PROG19() (setq a (entget (car (entsel "Select circle: ")))) (setq c (cdr (assoc 10 a))) (setq r (cdr (assoc 40 a))) (setq c2 (getpoint "\nSelect center for circle to move: ")) (command "circle" c2 r) ) ****************OUTPUT********************** C:PROG19 Command: PROG19 Select circle: Select center for circle to move:

20 Input x and y coordinates of n points and draw curve/line through them.

PROGRAM 20 ( defun c:PROG20() (setq pt1(list 2 5)) (setq pt2(list 3 6)) (setq pt3(list 8 7)) (setq pt4(list 5 8)) (command "pline"pt1 pt2 pt3 pt4 "") (command "spline"pt1 pt2 pt3 pt4"" "" "" ) ) ***************OUTPUT*********************

21 Select line from screen and find coordinates of end points and length of line.

PROGRAM 21 ( defun c:PROG21() (setq a (entget (car (entsel "Select line: ")))) (setq pt1 (cdr (assoc 10 a))) (setq pt2 (cdr (assoc 11 a))) (princ "End coordinates are ") (princ pt1) (princ pt2) (setq len (distance pt1 pt2)) (princ "Length of line is ") (princ len) (princ) ) ******************OUTPUT********************* C:PROG21 Command: PROG21 Select line: End coordinates are (-19.0157 20.4025 0.0)(-14.477 29.4409 0.0)Length of line is 10.1139

22 Select circle from screen and find coordinates of centre point, radius and area.

PROGRAM 22 ( defun c:PROG22() (setq a (entget (car (entsel "Select circle: ")))) (setq c (cdr (assoc 10 a))) (setq r (cdr (assoc 40 a))) (princ "Center of circle is ") (princ c) (princ "Radius of circle is ") (princ r) (setq a (* pi r r)) (princ "Area of circle is ") (princ a) (princ) ) *****************OUTPUT********************* Command: PROG22 Select circle: Center of circle is (-64.8579 67.7705 0.0) Radius of circle is 15.2586 Area of circle is 731.437

23 Select multiple entities of various types with ssget and find the types of entities.

PROGRAM 23 ( defun c:PROG23() (setq a (entget (car (entsel "Select object: ")))) (setq type (cdr (assoc 0 a))) (princ "Entity type is ") (princ type) (princ) ) **********************OUTPUT******************* C:PROG23 Command: PROG23 Select object: Entity type is CIRCLE

24 Draw rectangle.

PROGRAM 24 (defun C:PROG24() (setq p1(getpoint "\nEnter the first corner : ") p2(getpoint "\nEnter the second corner : ") p3(list (car p2) (cadr p1)) p4(list (car p1) (cadr p2)) ) (command"LINE" p1 p3 p2 p4 p1 "") (princ len ) ) ***********************************OUTPUT***************************** Command: PROG24 Enter the first corner : 9,9 Enter the second corner : 20,20

25 Draw triangle.

PROGRAM 25 (defun c:PROG25() (setq p1 (getpoint "\n Enter the first point of the triangle: ")) (setq p2 (getpoint "\n Enter the second point of the triangle: ")) (setq p3 (getpoint "\n Enter the third point of the triangle: ")) (command "line" p1 p2 p3 "c") )

****************************OUTPUT******************************* Command: PROG25 Enter the first point of the triangle: 10,20 Enter the second point of the triangle: 30,60 Enter the third point of the triangle: 20,80

26 Draw hexagon. PROGRAM 26 (defun c:PROG26() (setq p1(getpoint "enter start point")) (setq l(getreal "enter length of sides")) (setq a p1) (setq i 1) (setq angv(/ 360 6)) (setq ang 0) (command "pline" p1) (while (<= i 6) (setq p2(polar p1(* (/ pi 180) ang)1)) (command p2) (setq ang(+ ang angv)) (setq p1 p2) (setq i(+ i 1)) ) (command a "") (princ) )

****************************OUTPUT******************************** Command: PROG26 Enter start point : 10,10 Enter length of sides : 35

27 Input two strings from the user and perform various string operations. PROGRAM 27

(defun C:PROG27() (setq str1 "college") (setq str2 "P") (setq str4 (substr str1 1 4)) (princ str4) (setq int1 (strlen str4)) (princ int1) (setq str5 (strcat str4 "" str2)) (princ str5) (princ) ) ******************************OUTPUT********************************** Command: PROG27 coll4collP

28 Input two points from the user and perform various list filtering operations. PROGRAM 28

( defun c:PROG28() (setq pt1 (getpoint "\n First corner :")) (setq pt2 (getcorner pt1 "\n Last corner :")) (setq x1 (car pt1)) (setq x2 (car pt2)) (setq y1 (cadr pt1)) (setq y2 (cadr pt2)) (setq hor1 (- x2 x1)) (setq ver1 (- y2 y1)) (princ "\n Horizontal distance = ") (princ hor1) (princ "\n Vertical distance = ") (princ ver1) (princ) ) ****************OUTPUT******************** Command: PROG28 First corner :10,10 Last corner :20,20 Horizontal distance = 10.0 Vertical distance = 10.0

29 Find f(x) for two/three x values. PROGRAM 29

(defun c:PROG29() (setq x (getreal "\n Enter value of x: ")) (setq y (- (expt x 8) (/ 4 (expt x 9)) (/ 3 x) 4)) (princ "The answer is: ") (princ y) )

**************************OUTPUT*****************************

Command: PROG29 Enter value of x: 10 The answer is: 1.0e+0081.0e+008

30 Input height of equilateral triangle and find the length of side, area and perimeter. Draw the same triangle. PROGRAM 30

(defun c:PROG30() (setq pt1(getpoint "\n Enter first point: ") H(getreal "Enter height of equilateral triangle: ") L(/ H (sin (/ pi 3))) A(* 0.5 H L ) P(* 3 L) pt2(polar pt1 0 L) pt3(polar pt1 (/ pi 3) L) ) (command "pline" pt1 pt2 pt3 "C") (print L) (print A) (print P) )

**************************OUTPUT***************************** Enter first point: 9,9 Enter height of equilateral triangle: 7 8.0829 28.2902 24.2487

31 Input height and base of isosceles triangle and find the length of side, area and perimeter. Draw the same triangle. PROGRAM 31 (

defun c:PROG31() (setq pt1 (getpoint "\n enter 1st point")) (setq H (getreal "\n enter height of triangle")) (setq B (getreal "\n enter base of triangle")) (setq L (sqrt (+ (expt H 2) (expt (/ B 2 ) 2)))) (princ "Length is ") (princ L) (setq A (* 0.5 B H)) (princ "Area is ") (princ A) (setq P (+ (* L 2) B)) (princ "Perimeter is ") (princ P) (setq pt2(polar pt1 0 B)) (setq pt3(list(+ (nth 0 pt1) (/ B 2)) (+ (nth 1 pt1) H))) (command "pline" pt1 pt2 pt3 pt1 "") (princ) ) ***************OUTPUT********************* C:PROG31 Command: PROG31 Enter 1st point Enter height of triangle25 Enter base of triangle10 Length is 25.4951 Area is 125.0 Perimeter is 60.9902

32 Input diagonal of square and find the length of side, area and perimeter. Draw the same triangle. PROGRAM 32 ( defun c:PROG32()

(setq pt1 (getpoint"enter 1st point")) (setq D (getreal"enter diagonal length")) (setq l (/ D (sqrt 2))) (princ "Length of side ") (princ l) (setq A (expt l 2)) (princ "Area is ") (princ A) (setq p (* 4 l)) (princ "Perimeter is ") (princ p) (setq pt2 (polar pt1 0 l)) (setq pt3 (polar pt2 (/ pi 2) l)) (setq pt4 (polar pt3 pi l)) (command "pline" pt1 pt2 pt3 pt4 pt1 "") (princ) ) *************OUTPUT********************** C:PROG32 Command: PROG32 Enter 1st point Enter diagonal length20 Length of side 14.1421 Area is 200.0 Perimeter is 56.5685

33 Input area of equilateral triangle and find the length of side and perimeter. Draw the same triangle. PROGRAM 33 ( defun c:PROG33()

(setq a (getreal "enter area")) (setq pt1(getpoint"enter start point")) (setq l(sqrt(/ (* 2 a) (sin (/ pi 3))))) (princ "Length is ") (princ l) (setq p(* 3 l)) (princ "Perimeter is ") (princ p) (setq pt2(polar pt1 0 l)) (setq pt3(polar pt1 (/ pi 3) l)) (command "pline" pt1 pt2 pt3 pt1 "") ) **************OUTPUT********************* C:PROG33 Command: PROG33 Enter area : 45

34 Input area of circle and find radius and perimeter. Draw the same circle. PROGRAM 34 (defun c:PROG34()

(setq O(getpoint "\n enter centre") A(getreal "\n enter area of circle") R(sqrt (/ A pi)) P(* 2 pi R) ) (command "circle" O R "") (princ P) (princ R) ) **************************OUTPUT***************************** Enter centre : 10,10 Enter area of circle : 40 22.42 3.56825

35 Parametric program of nut, bolt, surface roughness symbols etc. PROGRAM 35 ( defun c:PROG35()

(setq c (getpoint "Select center of nut: ")) (setq r (getreal "Enter radius of nut: ")) (command "polygon" "6" c "i" r) (command "circle" c r) ) ****************OUTPUT******************* Command: PROG35 Select center of nut: Enter radius of nut: 5

36 Input two points from mouse and find distance and angle between the points. PROGRAM 36 (defun C:PROG36()

(setq A(getpoint "\n enter first point:") B(getpoint "\n enter second point:") L(distance A B) ) (print L) ) (defun C:ang() (setq A(getpoint "\n enter first point:") B(getpoint "\n enter second point:") L(angle A B) ) (print L) ) **********************************OUTPUT**************************************** Command: PROG36 Specify first point: 10,20 Specify second point: 20,30 Distance = 14.1421, Angle in XY Plane = 45, Angle from XY Plane = 0 Delta X = 10.0000, Delta Y = 10.0000, Delta Z = 0.0000 Command: ang Enter first point: 10,20 Enter second point: 20,30 0.785398 0.785398

37 Using string and data conversion functions draw rectangle. PROGRAM 37 (defun C:PROG37()

(setq A(GETSTRING "\n Enter X cordinate: ") B(GETSTRING "\n Enter Y cordinate: ") C(atof A) D(atof B) P(list C D) Q(GETSTRING "\n Enter X cordinate: ") R(GETSTRING "\n Enter Y cordinate: ") T(atof Q) U(atof R) J(list T U) H(list T D) G(list C U) ) (command "pline" P H J G P "") ) ********************************OUTPUT******************************* Command: PROG37 Enter X cordinate: 30 Enter Y cordinate: 50 Enter X cordinate: 20 Enter Y cordinate: 45

38 Using string and data conversion functions draw hexagon. PROGRAM 38 (defun C:PROG38()

(setq A(GETSTRING "\N Enter X cordinate: ") B(GETSTRING "\N ENTER Y cordinate: ") C(atof A) D(atof B) P(list C D) L(getreal "\n Enter length: ") Q(polar P 0.0 L) R(polar Q (/ pi 3.0) L) S(polar R (* 2 (/ pi 3.0)) L) T(polar S pi L) W(polar T (* 4 (/ pi 3.0)) L) ) (command "line" P Q R S T W P "") )

**************************OUTPUT**************************** Command: PROG38 Enter X cordinate: 10 Enter Y cordinate: 20 Enter length: 30

39 Using string and data conversion functions draw pentagon. PROGRAM 39 (defun C:PROG39()

(setq A(GETSTRING Enter X cordinate: ") B(GETSTRING Enter Y cordinate: ") C(atof A) D(atof B) P(list C D) L(getreal "\n Enter length: ") Q(polar P 0.0 L) R(polar Q (* 2 (/ pi 5.0)) L) S(polar R (* 4 (/ pi 5.0)) L) T(polar S (* 6 (/ pi 5.0)) L) ) (command "line" P Q R S T P "") )

**********************************OUTPUT******************************

Command: PROG39 Enter X cordinate: 10 Enter Y cordinate: 30 Enter length: 60

40 Input string and number and perform various string functions. PROGRAM 40 (defun c:PROG40()

(textscr) (setq r (getreal "\n Enter a real value: ")) (setq j (getstring "\n Enter your first name: ")) (setq rcon (rtos r)) (setq jlen (strlen j)) (setq jstr (itoa jlen)) (setq a "2") (setq b "3") (setq i1 (atoi a)) (setq r1 (atof b)) (setq res (* i1 r1)) (print (strcat "The value of real number you entered is " rcon)) (print (strcat "Your name contains " (strcat jstr " letters"))) (print (strcat (strcat "The multiplication of " a) (strcat " and " b))) (print res) ) **********************************OUTPUT****************************** Enter a real value: 50 Enter your first name: AMEYA "The value of real number you entered is 50 "Your name contains 5 letters" "The multiplication of 2 and 3" 6.0

Вам также может понравиться