40 programs solution
TRANSCRIPT
-
8/4/2019 40 Programs Solution
1/36
Name of Student:abc Roll No.2410
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.
(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 "")
)(
(
-
8/4/2019 40 Programs Solution
2/36
Name of Student:abc Roll No.2410
****************OUTPUT******************
Command: PROG1
Enter length of 1st side: 5Enter length of 2nd side: 3
Enter length of 3rd side: 7
Enter insertion point of triangle:
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
3/36
Name of Student:abc Roll No.2410
2. Input the diameter of flange. According to diameter of the flange create no of holes on the
flange.
(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: 20Enter p.c.d: 12
Enter hole radius :0.5
Enter no.of holes :8
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
4/36
Name of Student:abc Roll No.2410
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.
(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
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
5/36
Name of Student:abc Roll No.2410
4 Input the length of sides of triangle and find out which type of triangle it is and draw the same.
(
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"))
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
6/36
Name of Student:abc Roll No.2410
)
(
(
-
8/4/2019 40 Programs Solution
7/36
Name of Student:abc Roll No.2410
5 Draw a circle and pick a point on the screen. Find out whether the point lies inside or
Outside the circle.
(
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
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
8/36
Name of Student:abc Roll No.2410
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.
(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
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
9/36
Name of Student:abc Roll No.2410
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.
(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: 5
Select option for hatching 1 or 2 : 1
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
10/36
Name of Student:abc Roll No.2410
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.
(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 (
-
8/4/2019 40 Programs Solution
11/36
Name of Student:abc Roll No.2410
9 Draw square and circle (inscribe of circumscribe). Find out who is circumscribing
what according to dimension.
(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
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
12/36
Name of Student:abc Roll No.2410
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.
(
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
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
13/36
Name of Student:abc Roll No.2410
11 Find the summation of series like:
Sum=x+x^2+x^3+x^4+..
(defun c:PROG11_2()
(setq x (getint "Enter series variable: "))(setq n (getint "Enter length of series: "))(setq i 1)
(setq sum 0)
(while (
-
8/4/2019 40 Programs Solution
14/36
Name of Student:abc Roll No.2410
12 Input number of forces and find the resultant (magnitude and direction).
Draw the force polygon.
(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 (
-
8/4/2019 40 Programs Solution
15/36
Name of Student:abc Roll No.2410
13 Input the number of sides and draw polygon. (create polygon command)
(
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 (
-
8/4/2019 40 Programs Solution
16/36
Name of Student:abc Roll No.2410
14 Create polar array command for circle.
(
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
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
17/36
Name of Student:abc Roll No.2410
15 Circle. Create rectangular array command for
(
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 (
-
8/4/2019 40 Programs Solution
18/36
Name of Student:abc Roll No.2410
16 Create multiple copy command for circle.
(
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 move
Do you want to continue: y / n : n
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
19/36
Name of Student:abc Roll No.2410
17 Draw f(x) curve for given limits.
(
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: PROG17Enter a number: 6
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
20/36
Name of Student:abc Roll No.2410
18 Creating bill of material.
(
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: PROG18
Select insertion point:
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
21/36
Name of Student:abc Roll No.2410
19 Create move command if the object is selected with entsel.
(
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.
(
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*********************
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
22/36
Name of Student:abc Roll No.2410
21 Select line from screen and find coordinates of end points and length of line.
(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.44090.0)Length of line is 10.1139
22 Select circle from screen and find coordinates of centre point, radius and area.
(
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
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
23/36
Name of Student:abc Roll No.2410
23 Select multiple entities of various types with ssget and find the types of entities.
(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: PROG23
Select object:
Entity type is CIRCLE
24 Draw rectangle.
(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,9Enter the second corner : 20,20
25 Draw triangle.
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
24/36
Name of Student:abc Roll No.2410
(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,60Enter the third point of the triangle: 20,80
26 Draw hexagon.
(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 (
-
8/4/2019 40 Programs Solution
25/36
Name of Student:abc Roll No.2410
Enter start point : 10,10
Enter length of sides : 35
27 Input two strings from the user and perform various string operations.
(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
28 Input two points from the user and perform various list filtering operations.
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
26/36
Name of Student:abc Roll No.2410
(
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: PROG28First corner :10,10
Last corner :20,20Horizontal distance = 10.0
Vertical distance = 10.0
29 Find f(x) for two/three x values.
(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: 10The 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.
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
27/36
Name of Student:abc Roll No.2410
(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: 78.0829
28.290224.2487
31 Input height and base of isosceles triangle and find the length of side, area and perimeter.
Draw the same triangle.
(
defun c:PROG31()
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
28/36
Name of Student:abc Roll No.2410
(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: PROG31Enter 1st point
Enter height of triangle25
Enter base of triangle10Length 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.
(
defun c:PROG32()
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
29/36
Name of Student:abc Roll No.2410
(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: PROG32Enter 1st point
Enter diagonal length20
Length of side 14.1421Area 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.
(defun c:PROG33()(setq a (getreal "enter area"))
(setq pt1(getpoint"enter start point"))
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
30/36
Name of Student:abc Roll No.2410
(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: PROG33Enter area : 45
34 Input area of circle and find radius and perimeter. Draw the same circle.
(defun c:PROG34()
(setq O(getpoint "\n enter centre")
A(getreal "\n enter area of circle")R(sqrt (/ A pi))
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
31/36
Name of Student:abc Roll No.2410
P(* 2 pi R)
)
(command "circle" O R "")(princ P)
(princ R)
)
**************************OUTPUT*****************************Enter centre : 10,10
Enter area of circle : 40
22.423.56825
35 Parametric program of nut
(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)
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
32/36
Name of Student:abc Roll No.2410
)
****************OUTPUT*******************
Command: PROG35Select center of nut:
Enter radius of nut: 5
36 Input two points from mouse and find distance and angle between the points.
(defun C:PROG36()
(setq A(getpoint "\n enter first point:")
B(getpoint "\n enter second point:")L(distance A B)
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
33/36
Name of Student:abc Roll No.2410
)
(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,20
Specify second point: 20,30Distance = 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,20Enter second point: 20,30
0.785398 0.785398
37 Using string and data conversion functions draw rectangle.
(defun C:PROG37()
(setq A(GETSTRING "\n Enter X cordinate: ")
B(GETSTRING "\n Enter Y cordinate: ")
C(atof A)D(atof B)
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
34/36
Name of Student:abc Roll No.2410
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: PROG37Enter X cordinate: 30
Enter Y cordinate: 50
Enter X cordinate: 20Enter Y cordinate: 45
38 Using string and data conversion functions draw hexagon.
(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****************************
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
35/36
Name of Student:abc Roll No.2410
Command: PROG38
Enter X cordinate: 10
Enter Y cordinate: 20Enter length: 30
39 Using string and data conversion functions draw pentagon.
(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: 10Enter Y cordinate: 30
Enter length: 60
40 Input string and number and perform various string functions.
(defun c:PROG40()(textscr)
(setq r (getreal "\n Enter a real value: "))
(setq j (getstring "\n Enter your first name: "))
Computer Graphics Programs S.E.(Mechanical Engg.)
-
8/4/2019 40 Programs Solution
36/36
Name of Student:abc Roll No.2410
(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