50
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))

Auto Lisp

  • Upload
    ae1329

  • View
    103

  • Download
    7

Embed Size (px)

Citation preview

Page 1: Auto Lisp

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"))

))

Page 2: Auto Lisp

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

Page 3: Auto Lisp

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: PROG2Select center of flange: Enter diameter of flange: 20Enter p.c.d: 12Enter hole radius :0.5Enter no.of holes :8

Page 4: Auto Lisp

3 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: PROG3Enter one endpoint of diagonal of quadrilateral: Enter other endpoint of diagonal of quadrilateral:Quadrilateral is rectangle

Page 5: Auto Lisp

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"))

Page 6: Auto Lisp

)((<= (+ s1 s2) s3)(princ "These sides do not form a triangle"))

))*******************OUTPUT*******************C:PROG4Command: PROG4Enter length of 1st side: 5Enter length of 2nd side: 3Enter length of 3rd side: 7Enter insertion point of triangle:“Triangle is scalene”

Page 7: Auto Lisp

5 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:PROG5Command: PROG5Select center of circle: Enter radius of circle: 5Select any point on the screen: Point selected lies outside circle

Page 8: Auto Lisp

6 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:PROG6Command: PROG6Select object:Center of circle is (25.3331 13.5295 0.0)Radius of circle is 6.15538

Page 9: Auto Lisp

7 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: PROG7Select center of circle: Enter radius of circle: 5Select option for hatching 1 or 2 : 1

Page 10: Auto Lisp

8 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***************************

Page 11: Auto Lisp

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

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: PROG9Select circle: Select square: Circle is circumscribing square

Command: PROG9Select circle: Select square: Circle is inscribed in square

Page 12: Auto Lisp

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: PROG10Select starting point of line: Select endpoint of line:Select a point on the line: Selected point is to the right of midpoint of line

Page 13: Auto Lisp

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_2Command: PROG11_2Enter series variable: 2Enter length of series: 4Sum is -10

Page 14: Auto Lisp

12 Input number of forces and find the resultant (magnitude and direction). Draw 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: PROG12Enter start point: Enter no. of forces: 2Enter magnitude of force: 30Enter angle of force: 45Enter magnitude of force: 30Enter angle of force: 120Magnitude = 47.6012 Angle = 1.4399

Page 15: Auto Lisp

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:PROG13Command: PROG13Enter start point: Enter no. of sides: 5Enter length of sides: 10

Page 16: Auto Lisp

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_2Select center of circle:Enter radius of circle: 5

Page 17: Auto Lisp

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:PROG15Command: PROG15Select circle: Enter no. of rows: 3Enter no. of columns: 5Enter distance between rows: 10Enter distance between columns: 15

Page 18: Auto Lisp

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: PROG16Select circle:Select center for circle to move:Do you want to continue: y / n : ySelect center for circle to moveDo you want to continue: y / n : n

Page 19: Auto Lisp

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:PROG17Command: PROG17Enter a number: 6

Page 20: Auto Lisp

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:PROG18Command: PROG18Select insertion point:

Page 21: Auto Lisp

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:PROG19Command: PROG19Select circle:Select center for circle to move:

Page 22: Auto Lisp

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*********************

Page 23: Auto Lisp

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:PROG21Command: PROG21Select line: End coordinates are (-19.0157 20.4025 0.0)(-14.477 29.4409 0.0)Length of line is 10.1139

Page 24: Auto Lisp

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: PROG22Select circle: Center of circle is (-64.8579 67.7705 0.0)Radius of circle is 15.2586Area of circle is 731.437

Page 25: Auto Lisp

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:PROG23Command: PROG23Select object: Entity type is CIRCLE

Page 26: Auto Lisp

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: PROG24Enter the first corner : 9,9Enter the second corner : 20,20

Page 27: Auto Lisp

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

Page 28: Auto Lisp

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: PROG26Enter start point : 10,10Enter length of sides : 35

Page 29: Auto Lisp

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: PROG27coll4collP

Page 30: Auto Lisp

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

Page 31: Auto Lisp

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: PROG29Enter value of x: 10The answer is: 1.0e+0081.0e+008

Page 32: Auto Lisp

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,9Enter height of equilateral triangle: 78.082928.290224.2487

Page 33: Auto Lisp

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:PROG31Command: PROG31Enter 1st pointEnter height of triangle25Enter base of triangle10Length is 25.4951Area is 125.0Perimeter is 60.9902

Page 34: Auto Lisp

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:PROG32Command: PROG32Enter 1st pointEnter diagonal length20Length of side 14.1421Area is 200.0Perimeter is 56.5685

Page 35: Auto Lisp

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:PROG33Command: PROG33Enter area : 45

Page 36: Auto Lisp

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,10Enter area of circle : 4022.423.56825

Page 37: Auto Lisp

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: PROG35Select center of nut: Enter radius of nut: 5

Page 38: Auto Lisp

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: PROG36Specify first point: 10,20Specify second point: 20,30Distance = 14.1421, Angle in XY Plane = 45, Angle from XY Plane = 0Delta X = 10.0000, Delta Y = 10.0000, Delta Z = 0.0000

Command: angEnter first point: 10,20Enter second point: 20,300.785398 0.785398

Page 39: Auto Lisp

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

Page 40: Auto Lisp

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: PROG38Enter X cordinate: 10Enter Y cordinate: 20Enter length: 30

Page 41: Auto Lisp

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: PROG39Enter X cordinate: 10Enter Y cordinate: 30Enter length: 60

Page 42: Auto Lisp

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: 50Enter 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