; The Codewriting Workbook ; Creating Computational Architecture in AutoLISP ; by Robert J. Krawczyk ; Princeton Architectural Press, 2008 ; -------------------------------------------------------------------------- ; CH03.LSP ; -------------------------------------------------------------------------- ; Disclaimer: The information contained in this file is distributed on an ; "as is" basis, without warranty. Although every precaution has been taken ; in the preparation of this work, the author and publisher shall not have ; any liability to any person or entity with respect to any loss or damage ; caused or alleged to be caused directly or indirectly by the information ; contained in this work. ; -------------------------------------------------------------------------- (defun dtr (a) (* pi (/ a 180.0))) (defun rtd (a) (/ (* a 180.0) pi)) ; -------------------------------------------------------------------------- (defun rtoc (cpnt irad nsides / chord crad epnt) (setq chord (* 2.0 irad (sin (dtr (/ (/ 360.0 nsides) 2.0))))) (setq crad (sqrt (- (expt irad 2) (expt (/ chord 2.0) 2)))) (setq epnt (list (- (nth 0 cpnt) (/ chord 2.0)) (- (nth 1 cpnt) crad) (nth 2 cpnt))) (setq mpnt (list (nth 0 cpnt) (- (nth 1 cpnt) crad) (nth 2 cpnt))) (setq pperm (* chord nsides)) (setq parea (/ (* crad pperm) 2.0)) (list chord crad cpnt pperm parea) ) (defun ctor (epnt chord nsides / crad irad cpnt) (setq irad (/ chord (* 2 (sin (dtr (/ (/ 360.0 nsides) 2.0)))))) (setq crad (sqrt (- (expt irad 2) (expt (/ chord 2.0) 2)))) (setq cpnt (list (+ (nth 0 epnt) (/ chord 2.0)) (+ (nth 1 epnt) crad) (nth 2 epnt))) (setq mpnt (list (nth 0 cpnt) (- (nth 1 cpnt) crad) (nth 2 cpnt))) (setq pperm (* chord nsides)) (setq parea (/ (* crad pperm) 2.0)) (list irad crad cpnt pperm parea) ) ; -------------------------------------------------------------------------- (defun prog01 () (graphscr) ; get line points (prompt "\nDraw a line") (setq pnt1 (getpoint "\nFrom point:")) (setq pnt2 (getpoint pnt1 "\nTo point:")) ; draw line (command ".LINE" pnt1 pnt2 "") ; display coordinates (textscr) (princ "\nStart/end points: ") (princ pnt1) (princ "-") (princ pnt2) (princ) ) ; -------------------------------------------------------------------------- (defun prog02 () (graphscr) ; get line points (prompt "\nDraw a line") (setq pnt1 (getpoint "\nFrom point:")) (setq pnt2 (getpoint pnt1 "\nTo point:")) ; draw line (command ".LINE" pnt1 pnt2 "") ; compute offsets (setq xoff (- (nth 0 pnt2) (nth 0 pnt1))) (setq yoff (- (nth 1 pnt2) (nth 1 pnt1))) ; display coordinates (textscr) (princ "\nStart/end points: ") (princ pnt1) (princ "-") (princ pnt2) (princ "\nX offset: ") (princ xoff) (princ " Y offset: ") (princ yoff) (princ "\nLength: ") (princ (distance pnt1 pnt2)) (princ " ") (princ "Angle: ") (princ (rtd (angle pnt1 pnt2))) (princ) ) ; -------------------------------------------------------------------------- (defun prog03 () (graphscr) ; get corner and top points (prompt "\nDraw a right triangle") (setq pnt1 (getpoint "\nCorner of base:")) (setq pnt3 (getcorner pnt1 "\nTop corner:")) ; compute second point (setq pnt2 (list (nth 0 pnt3) (nth 1 pnt1) (nth 2 pnt1))) ; draw triangle (command ".PLINE" pnt1 pnt2 pnt3 pnt1 "") ; display triangle data (textscr) ; base and height (setq xside (abs (- (nth 0 pnt2) (nth 0 pnt1)))) (setq yside (abs (- (nth 1 pnt3) (nth 1 pnt2)))) (princ "\nBase: ") (princ xside) (princ " ") (princ "Height: ") (princ yside) ; area and perimeter (setq tarea (/ (* xside yside) 2)) (setq tperm (+ (distance pnt1 pnt2) (distance pnt2 pnt3) (distance pnt3 pnt1))) (princ "\nArea: ") (princ tarea) (princ " ") (princ "Perimeter: ") (princ tperm) (princ) ) ; -------------------------------------------------------------------------- (defun prog04 () (graphscr) ; get corner points (prompt "\nDraw a rectangle, by corners") (setq pnt1 (getpoint "\nFirst corner:")) (setq pnt3 (getcorner pnt1 "\nSecond corner:")) ; compute other two points (setq pnt2 (list (nth 0 pnt3) (nth 1 pnt1) (nth 2 pnt1))) (setq pnt4 (list (nth 0 pnt1) (nth 1 pnt3) (nth 2 pnt1))) ; draw rectangle (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") ; display rectangle data (textscr) ; length and width (setq xside (abs (- (nth 0 pnt2) (nth 0 pnt1)))) (setq yside (abs (- (nth 1 pnt3) (nth 1 pnt2)))) (princ "\nLength: ") (princ xside) (princ " ") (princ "Width: ") (princ yside) ; area and perimeter (setq tarea (* xside yside)) (setq tperm (+ (* xside 2) (* yside 2))) (princ "\nArea: ") (princ tarea) (princ " ") (princ "Perimeter: ") (princ tperm) (princ) ) ; -------------------------------------------------------------------------- (defun prog05 () (graphscr) ; get center point and dimensions (prompt "\nDraw a rectangle, by center point") (setq pnt0 (getpoint "\nCenter:")) (setq xside (getdist "\nEnter length:")) (setq yside (getdist "\nEnter width:")) ; compute corner points (setq pnt1 (list (- (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt4 (list (- (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) ; draw rectangle (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") ; display rectangle data (textscr) (princ "\nLength: ") (princ (rtos xside)) (princ " ") (princ "Width: ") (princ (rtos yside)) (setq tarea (/ (* xside yside) 144)) (setq tperm (+ (* xside 2) (* yside 2))) (princ "\nArea: ") (princ tarea) (princ " ") (princ "Perimeter: ") (princ (rtos tperm)) (princ) ) ; -------------------------------------------------------------------------- (defun prog05a () (graphscr) ; get center point and dimensions (prompt "\nDraw a rectangle, by bottom midpoint") (setq pnt0 (getpoint "\nCenter:")) (setq xside (getdist "\nEnter length:")) (setq yside (getdist "\nEnter width:")) ; compute corner points (setq pnt1 (list (- (nth 0 pnt0) (/ xside 2)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) (/ xside 2)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) yside) (nth 2 pnt0))) (setq pnt4 (list (- (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) yside) (nth 2 pnt0))) ; draw rectangle (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") ; display rectangle data (textscr) (princ "\nLength: ") (princ (rtos xside)) (princ " ") (princ "Width: ") (princ (rtos yside)) (setq tarea (/ (* xside yside) 144)) (setq tperm (+ (* xside 2) (* yside 2))) (princ "\nArea: ") (princ tarea) (princ " ") (princ "Perimeter: ") (princ (rtos tperm)) (princ) ) ; -------------------------------------------------------------------------- (defun prog06 () (graphscr) ; get center point and dimensions (prompt "\nDraw a I-beam, by center") (setq pnt0 (getpoint "\nCenter:")) (setq dbeam (getdist "\nEnter depth:")) (setq wbeam (getdist "\nEnter width:")) (setq wthk (getdist "\nEnter web thickness:")) (setq fthk (getdist "\nEnter flange thickness:")) ; compute corner points ; starting lower left corner (setq pnt1 (list (- (nth 0 pnt0) (/ wbeam 2)) (- (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) (/ wbeam 2)) (- (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) (/ wbeam 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt4 (list (+ (nth 0 pnt0) (/ wthk 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt5 (list (+ (nth 0 pnt0) (/ wthk 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt6 (list (+ (nth 0 pnt0) (/ wbeam 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt7 (list (+ (nth 0 pnt0) (/ wbeam 2)) (+ (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt8 (list (- (nth 0 pnt0) (/ wbeam 2)) (+ (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt9 (list (- (nth 0 pnt0) (/ wbeam 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt10 (list (- (nth 0 pnt0) (/ wthk 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt11 (list (- (nth 0 pnt0) (/ wthk 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt12 (list (- (nth 0 pnt0) (/ wbeam 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) ; draw I-Beam (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 pnt7 pnt8 pnt9 pnt10 pnt11 pnt12 pnt1 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog06a () (graphscr) ; get center point and dimensions (prompt "\nDraw a 3D I-beam, by center") (setq pnt0 (getpoint "\nCenter:")) (setq dbeam (getdist "\nEnter depth:")) (setq wbeam (getdist "\nEnter width:")) (setq wthk (getdist "\nEnter web thickness:")) (setq fthk (getdist "\nEnter flange thickness:")) (setq bhgt (getdist "\nEnter beam height:")) ; compute corner points ; starting lower left corner (setq pnt1 (list (- (nth 0 pnt0) (/ wbeam 2)) (- (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) (/ wbeam 2)) (- (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) (/ wbeam 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt4 (list (+ (nth 0 pnt0) (/ wthk 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt5 (list (+ (nth 0 pnt0) (/ wthk 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt6 (list (+ (nth 0 pnt0) (/ wbeam 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt7 (list (+ (nth 0 pnt0) (/ wbeam 2)) (+ (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt8 (list (- (nth 0 pnt0) (/ wbeam 2)) (+ (nth 1 pnt0) (/ dbeam 2)) (nth 2 pnt0))) (setq pnt9 (list (- (nth 0 pnt0) (/ wbeam 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt10 (list (- (nth 0 pnt0) (/ wthk 2)) (- (+ (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt11 (list (- (nth 0 pnt0) (/ wthk 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) (setq pnt12 (list (- (nth 0 pnt0) (/ wbeam 2)) (+ (- (nth 1 pnt0) (/ dbeam 2)) fthk) (nth 2 pnt0))) ; draw I-Beam (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 pnt7 pnt8 pnt9 pnt10 pnt11 pnt12 pnt1 "") ; extrude section (command ".EXTRUDE" "last" "" bhgt) ; for versions prior to 2007 add a taper parameter ;(command ".EXTRUDE" "last" "" bhght "0") (princ) ) ; -------------------------------------------------------------------------- (defun prog07 () (graphscr) ; get corner points (prompt "\nDraw a nested triangle") (setq pnt1 (getpoint "\nFirst point:")) (setq pnt2 (getpoint "\nSecond point:")) (setq pnt3 (getpoint "\nThird point:")) ; draw outside triangle (command ".PLINE" pnt1 pnt2 pnt3 pnt1 "") ; compute midpoints (setq ang (angle pnt1 pnt2)) (setq dist (distance pnt1 pnt2)) (setq pnt4 (polar pnt1 ang (/ dist 2))) (setq ang (angle pnt2 pnt3)) (setq dist (distance pnt2 pnt3)) (setq pnt5 (polar pnt2 ang (/ dist 2))) (setq ang (angle pnt3 pnt1)) (setq dist (distance pnt3 pnt1)) (setq pnt6 (polar pnt3 ang (/ dist 2))) ; draw inside triangle (command ".PLINE" pnt4 pnt5 pnt6 pnt4 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog07a () (graphscr) ; get corner points (prompt "\nDraw a nested 3D rectangle") (setq pnt1 (getpoint "\nFirst point:")) (setq pnt2 (getpoint "\nSecond point:")) (setq pnt3 (getpoint "\nThird point:")) (setq pnt4 (getpoint "\nFourth point:")) ; draw outside rectangle (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") ; compute midpoints (setq ang (angle pnt1 pnt2)) (setq dist (distance pnt1 pnt2)) (setq pnt5 (polar pnt1 ang (/ dist 2))) (setq ang (angle pnt2 pnt3)) (setq dist (distance pnt2 pnt3)) (setq pnt6 (polar pnt2 ang (/ dist 2))) (setq ang (angle pnt3 pnt4)) (setq dist (distance pnt3 pnt4)) (setq pnt7 (polar pnt3 ang (/ dist 2))) (setq ang (angle pnt4 pnt1)) (setq dist (distance pnt4 pnt1)) (setq pnt8 (polar pnt4 ang (/ dist 2))) ; draw inside rectangle (command ".PLINE" pnt5 pnt6 pnt7 pnt8 pnt5 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog08 () (graphscr) ; get corner points (prompt "\nDraw circle based on area") (setq carea (getreal "\nArea:")) (setq pnt0 (getpoint "\nCenter:")) ; compute radius (setq crad (sqrt (/ (* carea 144) pi))) ; draw circle (command ".CIRCLE" pnt0 crad) (princ) ) ; -------------------------------------------------------------------------- (defun xprog08 () (graphscr) ; get corner points (prompt "\nDraw a parallelogram") (setq pnt1 (getpoint "\nFirst bottom corner:")) (setq pnt2 (getpoint pnt1 "\nSecond bottom corner:")) (setq pnt3 (getpoint pnt2 "\nTop corner:")) ; mod bottom point (setq pnt2 (list (nth 0 pnt2) (nth 1 pnt1) (nth 2 pnt1))) ; compute fourth point (setq base (distance pnt1 pnt2)) (setq pnt4 (list (- (nth 0 pnt3) base) (nth 1 pnt3) (nth 2 pnt1))) ; draw parallelogram (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (princ) ) ; -------------------------------------------------------------------------- ; -------------------------------------------------------------------------- (defun prog09a () (graphscr) ; get corner and edge (prompt "\nDraw a pentagon, corner and edge length") (setq pnt0 (getpoint "\nBottom-left corner:")) (setq ledge (getdist "\nEdge length:")) ; set turning angle (setq tang (/ 360.0 5)) ; set starting angle and point (setq sang 0.0) (setq pnt1 pnt0) ; compute end of first edge (setq pnt2 (polar pnt1 (dtr sang) ledge)) ; inc turning angle (setq sang (+ sang tang)) ; compute end of second edge (setq pnt3 (polar pnt2 (dtr sang) ledge)) ; inc turning angle (setq sang (+ sang tang)) ; compute end of third edge (setq pnt4 (polar pnt3 (dtr sang) ledge)) ; inc turning angle (setq sang (+ sang tang)) ; compute end of fourth edge (setq pnt5 (polar pnt4 (dtr sang) ledge)) ; draw polygon (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 "c") (princ) ) ; -------------------------------------------------------------------------- (defun prog09b () (graphscr) ; get corner and edge (prompt "\nDraw a pentagon, midpoint and edge length") (setq pnt0 (getpoint "\nBottom edge midpoint:")) (setq ledge (getdist "\nEdge length:")) ; set turning angle (setq tang (/ 360.0 5)) ; set starting angle and point (setq sang 0.0) (setq pnt1 (list (- (nth 0 pnt0) (/ ledge 2)) (nth 1 pnt0) (nth 2 pnt0))) ; compute end of first edge (setq pnt2 (polar pnt1 (dtr sang) ledge)) ; inc turning angle (setq sang (+ sang tang)) ; compute end of second edge (setq pnt3 (polar pnt2 (dtr sang) ledge)) ; inc turning angle (setq sang (+ sang tang)) ; compute end of third edge (setq pnt4 (polar pnt3 (dtr sang) ledge)) ; inc turning angle (setq sang (+ sang tang)) ; compute end of fourth edge (setq pnt5 (polar pnt4 (dtr sang) ledge)) ; draw polygon (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 "c") (princ) ) ; -------------------------------------------------------------------------- (defun prog09c () (graphscr) ; get center and radius (prompt "\nDraw a pentagon, center and radius") (setq pnt0 (getpoint "\nCenter:")) (setq radius (getdist "\nRadius:")) ; set turning angle (setq tang (/ 360.0 5)) ; set starting angle (setq sang 0.0) ; compute first point (setq pnt1 (polar pnt0 (dtr sang) radius)) ; inc turning angle (setq sang (+ sang tang)) ; compute second point (setq pnt2 (polar pnt0 (dtr sang) radius)) ; inc turning angle (setq sang (+ sang tang)) ; compute third point (setq pnt3 (polar pnt0 (dtr sang) radius)) ; inc turning angle (setq sang (+ sang tang)) ; compute fourth point (setq pnt4 (polar pnt0 (dtr sang) radius)) ; inc turning angle (setq sang (+ sang tang)) ; compute fifth point (setq pnt5 (polar pnt0 (dtr sang) radius)) ; draw polygon (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 "c") (princ) ) ; -------------------------------------------------------------------------- ; -------------------------------------------------------------------------- (defun prog10 () (graphscr) ; get center and dimensions (prompt "\nDraw a rounded rectangle") (setq pnt0 (getpoint "\nCenter:")) (setq xdim (getdist "\nLength:")) (setq ydim (getdist "\nWidth:")) ; starting point for pline (setq pnt1 (list (- (nth 0 pnt0) (/ (- xdim ydim) 2)) (- (nth 1 pnt0) (/ ydim 2)) (nth 2 pnt0))) ; start of right curve (setq pnt2 (list (+ (nth 0 pnt0) (/ (- xdim ydim) 2)) (- (nth 1 pnt0) (/ ydim 2)) (nth 2 pnt0))) ; end of right curve (setq pnt3 (list (+ (nth 0 pnt0) (/ (- xdim ydim) 2)) (+ (nth 1 pnt0) (/ ydim 2)) (nth 2 pnt0))) ; start of left curve (setq pnt4 (list (- (nth 0 pnt0) (/ (- xdim ydim) 2)) (+ (nth 1 pnt0) (/ ydim 2)) (nth 2 pnt0))) ; draw PLINE (command ".PLINE" pnt1 pnt2 "a" pnt3 "l" pnt4 "a" "cl") (princ) ) ; -------------------------------------------------------------------------- (defun prog11 () (graphscr) ; get center, outside radius, and thickness (prompt "\nDraw a circular tube") (setq pnt0 (getpoint "\nCenter:")) (setq crad (getdist "\nOutside radius:")) (setq cthk (getdist "\nThickness:")) ; outside circle (command ".CIRCLE" pnt0 crad) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast))) ; inside circle (command ".CIRCLE" pnt0 (- crad cthk)) ; make region (command ".REGION" "last" "" ) ; place into a second selection list (setq obj2 (ssadd (entlast))) ; subtract inside from outside (command ".SUBTRACT" obj1 "" obj2 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog11a () (graphscr) ; get center, outside radius, and thickness (prompt "\nDraw a quatrefoil opening in a plate") (setq pnt0 (getpoint "\nCenter:")) (setq crad (getdist "\nOutside radius:")) (setq cthk (getdist "\nThickness:")) ; outside circle (command ".CIRCLE" pnt0 crad) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast))) ; inside circle radius (setq inrad (/ (- crad cthk) 2.0)) ; inside circle (setq cpt (list (- (nth 0 pnt0) inrad) (nth 1 pnt0) (nth 2 pnt0))) (command ".CIRCLE" cpt inrad) ; make region (command ".REGION" "last" "" ) ; place into a second selection list (setq obj2 (ssadd (entlast))) ; inside circle (setq cpt (list (+ (nth 0 pnt0) inrad) (nth 1 pnt0) (nth 2 pnt0))) (command ".CIRCLE" cpt inrad) ; make region (command ".REGION" "last" "" ) ; place into a second selection list (setq obj2 (ssadd (entlast) obj2)) ; inside circle (setq cpt (list (nth 0 pnt0) (+ (nth 1 pnt0) inrad) (nth 2 pnt0))) (command ".CIRCLE" cpt inrad) ; make region (command ".REGION" "last" "" ) ; place into a second selection list (setq obj2 (ssadd (entlast) obj2)) ; inside circle (setq cpt (list (nth 0 pnt0) (- (nth 1 pnt0) inrad) (nth 2 pnt0))) (command ".CIRCLE" cpt inrad) ; make region (command ".REGION" "last" "" ) ; place into a second selection list (setq obj2 (ssadd (entlast) obj2)) ; subtract inside from outside (command ".SUBTRACT" obj1 "" obj2 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog11b () (graphscr) ; get center, radius (prompt "\nDraw a trefoil with hole") (setq pnt0 (getpoint "\nCenter:")) (setq crad (getdist "\nRadius:")) ; first circle (setq pnt1 (polar pnt0 (dtr 90) crad)) (command ".CIRCLE" pnt1 crad) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast))) ; second circle (setq pnt2 (polar pnt0 (dtr 210) crad)) (command ".CIRCLE" pnt2 crad) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; third circle (setq pnt3 (polar pnt0 (dtr 330) crad)) (command ".CIRCLE" pnt3 crad) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; union are three (command ".UNION" obj1 "") ; place union into selection (setq obj1 (ssadd (entlast))) ; inside circular hole (command ".CIRCLE" pnt0 (* crad 0.25)) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj2 (ssadd (entlast))) ; subtract (command ".SUBTRACT" obj1 "" obj2 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog11c () (graphscr) ; get center point and dimensions (prompt "\nDraw a cross opening in an elliptical plate") (setq pnt0 (getpoint "\nCenter:")) (setq xside (getdist "\nEnter length:")) (setq yside (getdist "\nEnter width:")) (setq cthk (getdist "\nEnter cross thickness:")) (setq pthk (getdist "\nEnter plate edge:")) ; compute corner points ; starting lower left corner (setq pnt1 (list (- (nth 0 pnt0) cthk) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) cthk) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) cthk) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt4 (list (+ (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt5 (list (+ (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt6 (list (+ (nth 0 pnt0) cthk) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt7 (list (+ (nth 0 pnt0) cthk) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt8 (list (- (nth 0 pnt0) cthk) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt9 (list (- (nth 0 pnt0) cthk) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt10 (list (- (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt11 (list (- (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt12 (list (- (nth 0 pnt0) cthk) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) ; draw cross (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 pnt7 pnt8 pnt9 pnt10 pnt11 pnt12 pnt1 "") ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj2 (ssadd (entlast))) ; draw ellipse (setq xpt (list (+ (nth 0 pnt0) (+ (/ xside 2) pthk)) (nth 1 pnt0) (nth 2 pnt0))) (setq ypt (list (nth 0 pnt0) (+ (nth 1 pnt0) (+ (/ yside 2) pthk)) (nth 2 pnt0))) (command ".ELLIPSE" "c" pnt0 xpt ypt) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast))) ; subtract (command ".SUBTRACT" obj1 "" obj2 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog11d () (graphscr) ; get center point and dimensions (prompt "\nDraw a 3D cross opening in an elliptical plate") (setq pnt0 (getpoint "\nCenter:")) (setq xside (getdist "\nEnter length:")) (setq yside (getdist "\nEnter width:")) (setq cthk (getdist "\nEnter cross thickness:")) (setq pthk (getdist "\nEnter plate edge:")) (setq plthk (getdist "\nEnter plate thickness:")) ; compute corner points ; starting lower left corner (setq pnt1 (list (- (nth 0 pnt0) cthk) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) cthk) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) cthk) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt4 (list (+ (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt5 (list (+ (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt6 (list (+ (nth 0 pnt0) cthk) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt7 (list (+ (nth 0 pnt0) cthk) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt8 (list (- (nth 0 pnt0) cthk) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt9 (list (- (nth 0 pnt0) cthk) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt10 (list (- (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt11 (list (- (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt12 (list (- (nth 0 pnt0) cthk) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) ; draw cross (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 pnt7 pnt8 pnt9 pnt10 pnt11 pnt12 pnt1 "") ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj2 (ssadd (entlast))) ; draw ellipse (setq xpt (list (+ (nth 0 pnt0) (+ (/ xside 2) pthk)) (nth 1 pnt0) (nth 2 pnt0))) (setq ypt (list (nth 0 pnt0) (+ (nth 1 pnt0) (+ (/ yside 2) pthk)) (nth 2 pnt0))) (command ".ELLIPSE" "c" pnt0 xpt ypt) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast))) ; subtract (command ".SUBTRACT" obj1 "" obj2 "") ; extrude plate (command ".EXTRUDE" "last" "" plthk) ; for versions prior to 2007 add a taper parameter ;(command ".EXTRUDE" "last" "" plthk "0") (princ) ) ; -------------------------------------------------------------------------- (defun prog11e () (graphscr) ; get center point and dimensions (prompt "\nDraw a 3D cross in an elliptical plate") (setq pnt0 (getpoint "\nCenter:")) (setq xside (getdist "\nEnter length:")) (setq yside (getdist "\nEnter width:")) (setq cthk (getdist "\nEnter cross thickness:")) (setq pthk (getdist "\nEnter plate edge:")) (setq plthk (getdist "\nEnter plate thickness:")) ; compute corner points ; starting lower left corner (setq pnt1 (list (- (nth 0 pnt0) cthk) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) cthk) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) cthk) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt4 (list (+ (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt5 (list (+ (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt6 (list (+ (nth 0 pnt0) cthk) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt7 (list (+ (nth 0 pnt0) cthk) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt8 (list (- (nth 0 pnt0) cthk) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt9 (list (- (nth 0 pnt0) cthk) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt10 (list (- (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt11 (list (- (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) (setq pnt12 (list (- (nth 0 pnt0) cthk) (- (nth 1 pnt0) cthk) (nth 2 pnt0))) ; draw cross (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt5 pnt6 pnt7 pnt8 pnt9 pnt10 pnt11 pnt12 pnt1 "") ; extrude cross (command ".EXTRUDE" "last" "" (* plthk 2)) ; for versions prior to 2007 add a taper parameter ;(command ".EXTRUDE" "last" "" plthk "0") ; place into selection list (setq obj2 (ssadd (entlast))) ; draw ellipse (setq xpt (list (+ (nth 0 pnt0) (+ (/ xside 2) pthk)) (nth 1 pnt0) (nth 2 pnt0))) (setq ypt (list (nth 0 pnt0) (+ (nth 1 pnt0) (+ (/ yside 2) pthk)) (nth 2 pnt0))) (command ".ELLIPSE" "c" pnt0 xpt ypt) ; extrude plate (command ".EXTRUDE" "last" "" plthk) ; for versions prior to 2007 add a taper parameter ;(command ".EXTRUDE" "last" "" plthk "0") ; place into selection list (setq obj1 (ssadd (entlast))) ; union plate and cross (command ".UNION" obj1 obj2 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog12 () (graphscr) ; get center, radius (prompt "\nDraw a set of five circles") (setq pnt0 (getpoint "\nCenter:")) (setq crad (getdist "\nCenter circle radius:")) (setq erad (getdist "\nEdge circle radius:")) (setq bname (getstring "\nBLOCK name:")) ; center circle (command ".CIRCLE" pnt0 crad) ; place into selection list (setq obj1 (ssadd (entlast))) ; first circle (setq pnt1 (polar pnt0 (dtr 0) (+ crad erad))) (command ".CIRCLE" pnt1 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; second circle (setq pnt2 (polar pnt0 (dtr 90) (+ crad erad))) (command ".CIRCLE" pnt2 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; third circle (setq pnt3 (polar pnt0 (dtr 180) (+ crad erad))) (command ".CIRCLE" pnt3 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; fourth circle (setq pnt4 (polar pnt0 (dtr 270) (+ crad erad))) (command ".CIRCLE" pnt4 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; outside circle (command ".CIRCLE" pnt0 (+ crad (* erad 2))) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; make into a BLOCK (command ".BLOCK" bname pnt0 obj1 "") ; INSERT back (command ".INSERT" bname pnt0 "1" "1" "0") (princ) ) ; -------------------------------------------------------------------------- (defun prog12a () (graphscr) ; get center, radius (prompt "\nDraw a set of five circles") (setq pnt0 (getpoint "\nCenter:")) (setq crad (getdist "\nCenter circle radius:")) (setq erad (getdist "\nEdge circle radius:")) (setq bname(rtos (getvar "date") 2 10)) ; center circle (command ".CIRCLE" pnt0 crad) ; place into selection list (setq obj1 (ssadd (entlast))) ; first circle (setq pnt1 (polar pnt0 (dtr 0) (+ crad erad))) (command ".CIRCLE" pnt1 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; second circle (setq pnt2 (polar pnt0 (dtr 90) (+ crad erad))) (command ".CIRCLE" pnt2 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; third circle (setq pnt3 (polar pnt0 (dtr 180) (+ crad erad))) (command ".CIRCLE" pnt3 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; fourth circle (setq pnt4 (polar pnt0 (dtr 270) (+ crad erad))) (command ".CIRCLE" pnt4 erad) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; outside circle (command ".CIRCLE" pnt0 (+ crad (* erad 2))) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; make into a BLOCK (command ".BLOCK" bname pnt0 obj1 "") ; INSERT back (command ".INSERT" bname pnt0 "1" "1" "0") (princ) ) ; -------------------------------------------------------------------------- ; -------------------------------------------------------------------------- ; doline - draw a line (defun doline (pnt1 pnt2 / ) ; draw the line (command ".LINE" pnt1 pnt2 "") (princ) ) ; -------------------------------------------------------------------------- (defun dorectcen (pnt0 xside yside / pnt1 pnt2 pnt3 pnt4) ; compute points (setq pnt1 (list (- (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) (/ xside 2)) (- (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) (setq pnt4 (list (- (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) (/ yside 2)) (nth 2 pnt0))) ; draw rectangle (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (princ) ) ; -------------------------------------------------------------------------- (defun dorectbtm (pnt0 xside yside / pnt1 pnt2 pnt3 pnt4) ; compute points (setq pnt1 (list (- (nth 0 pnt0) (/ xside 2)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt2 (list (+ (nth 0 pnt0) (/ xside 2)) (nth 1 pnt0) (nth 2 pnt0))) (setq pnt3 (list (+ (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) yside) (nth 2 pnt0))) (setq pnt4 (list (- (nth 0 pnt0) (/ xside 2)) (+ (nth 1 pnt0) yside) (nth 2 pnt0))) ; draw rectangle (command ".PLINE" pnt1 pnt2 pnt3 pnt4 pnt1 "") (princ) ) ;-------------------------------------------------------------------------- (defun docring (pnt0 crad cthk / obj1 obj2) ; requires center, outside radius, and thicknes ; outside circle (command ".CIRCLE" pnt0 crad) ; make region (command ".REGION" "last" "" ) ; place into selection list (setq obj1 (ssadd (entlast))) ; inside circle (command ".CIRCLE" pnt0 (- crad cthk)) ; make region (command ".REGION" "last" "" ) ; place into a second selection list (setq obj2 (ssadd (entlast))) ; subtract inside from outside (command ".SUBTRACT" obj1 "" obj2 "") (princ) ) ; -------------------------------------------------------------------------- (defun prog13 () (graphscr) ; get center, radius (prompt "\nDraw a 3D ring trefoil") (setq pnt0 (getpoint "\nCenter:")) (setq rrad (getdist "\nRing radius:")) (setq rthk (getdist "\nRing thickness:")) ; first ring (setq pnt1 (polar pnt0 (dtr 90) rrad)) (docring pnt1 rrad rthk) ; place into selection list (setq obj1 (ssadd (entlast))) ; second ring (setq pnt2 (polar pnt0 (dtr 210) rrad)) (docring pnt2 rrad rthk) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; third ring (setq pnt3 (polar pnt0 (dtr 330) rrad)) (docring pnt3 rrad rthk) ; place into selection list (setq obj1 (ssadd (entlast) obj1)) ; union are three (command ".UNION" obj1 "") ; extrude rings (command ".EXTRUDE" "last" "" rthk) ; for versions prior to 2007 add a taper parameter ;(command ".EXTRUDE" "last" "" rthk "0") (princ) ) ; -------------------------------------------------------------------------- ; -------------------------------------------------------------------------- ; --------------------------------------------------------------------------