(defun C:gear ()0 _4 f6 N/ ]+ y, ~' u4 E
(setq numt nil
8 K$ r6 a0 j2 Y diap nil
3 |% E/ T$ [5 ` l& B' X prsa nil) q4 O. c9 B$ N, z8 W, ? k' @
pnts nil
0 ~/ h+ G/ u4 j% I4 V' {7 B test nil6 p! W/ s- L% Q f4 d- I
pwd nil5 [/ {+ _' t! \: x$ F, O
)
8 j: }5 Z9 q: L" U. M% W
7 }! D0 m4 C, V2 A3 e7 b (setq numt (getint "Number of teeth:<24>")) y( f7 `2 }/ p
(if (= numt nil)5 q# }5 b7 W! X( b$ t9 d
(setq numt 24)5 N/ S1 t; U& |4 g8 B
)
" B1 [. F( Z/ p% U4 Z' E6 T' b& k (setq diap (getreal "Modulus of gear:<0.5> "))
: r" ]8 K* k1 B y, I v- E (if (= diap nil)
t) q% g8 S4 a2 c! W, L2 w. E- @6 V (setq diap (/ 1 0.5))% g# B1 E! R) h( G6 o
(setq diap (/ 1 diap))1 v- ?* k" F9 x8 g3 n
)( Y& u/ B4 T, i+ m
(setq prsa (getreal "Pressure angle:<20.0> "))
! @8 j& P% G L7 f0 ~( F+ P (if (= prsa nil)3 u2 Y/ J/ l& q( Y/ \7 ^3 r
(setq prsa 20.0)
. l( i) g, K; T! Q( S )7 ~3 n) b$ z; a
(setq pnts (getint "number of points on curve:<40> "))
7 `& Y' V5 n3 Y3 l (if (= pnts nil)
; c" F* ^* m" R- E, H+ w (setq pnts 40)/ w+ i- L) O, C: z
)
# p( h8 c2 X* t5 s& Q- t; g
4 `" k: T1 D' U* w3 y; (setq pwd (getreal "Please input password:"))( h# T. w* s1 n: q4 @" Q* F
; (if (/= pwd 8833)1 U2 @- G/ o! ]1 Y( J5 G6 p/ `: ^
; (setq numt 0)
3 C& E) S' W! U/ ^- s; )9 o1 q# `- j3 y1 E
; (if (= pwd nil)
" l4 b" O6 ?$ d/ J- }; (setq numt 0)
2 a' j0 b" z4 W: e& l; )6 O2 @ v1 ^. y2 Z* B
;
! j4 y: p2 x9 w0 [$ Q' S3 _ (command "osnap" "non")- b: Y' F- L/ p
(setvar "cmdecho" 0). \* c( V9 {% k* {/ t% v+ c b; N
(setq oldvar (getvar "pickbox"))
) ^+ K) O _* t3 n; r5 M6 o! M (setvar "pickbox" 0); h9 i* D6 X* q0 @0 {4 z
(setvar "aperture" 1)& d6 o( h+ w, D7 l9 A, m% K- l2 G
(command "osmode" "0" ). \3 f- P* s5 B; R+ D8 R% x
;( | }+ h# [; X& D! |$ O
(setq prsa (/ (* prsa pi) 180.0))7 U8 s' u; W5 X1 `$ c2 ^
(setq pitd (/ numt diap)). l( m1 @1 f7 K
(setq outd (/ (+ numt 2) diap))' h4 @2 Q' P9 _& M. J; e+ T. c) B
(setq basr (/ (* pitd (cos prsa)) 2))) W/ a6 |+ X7 e
(setq orad (/ outd 2.0))
1 W5 {1 w0 ?& g (setq z (- (expt orad 2.0) (expt basr 2.0)))* @% e' F8 I1 c+ C& A0 \& b
(setq x (sqrt z))
- A& d7 m( ^: k7 B$ V (setq paodd (atan (/ x basr)))
+ e. ^7 `" S% g2 f, \$ E/ U (setq incr (/ paodd pnts))
$ Y% \" S! H, u( |8 | (setq p 0.0)
0 R2 N/ a' h- k( G (setq pitr (/ pitd 2.0))
3 g6 y6 r6 L1 Y+ y6 i7 W (setq pang (/ 360. (* numt 4.0)))7 x3 E/ R0 S- b
(setq pang (/ (* pang pi) 180.0))
: E! ^" w+ @/ n, R (graphscr)
5 s4 A2 N9 x& i (setq p2 (getpoint "center of gear:"))
?- i; A: Z' ~1 a I4 j2 e% E/ D (setq y2 (cadr p2))
9 D# q5 P, X3 ?+ U8 o (setq x2 (car p2))
@: `# |$ D W" S- s5 e (setq r0 (/ (/ (- numt 2.5) diap) 2)). t- n k% [. o6 H% K4 X5 u
(setq r1 (/ 0.2 diap))
7 V' G8 V9 \ J% K, t (setq h (sqrt (- (* (+ r1 r0) (+ r1 r0)) (* r1 r1))))
; c$ `. z) |# M, E6 w* E* G (setq ang0 (/ (* pi 2) numt))
; V" D5 e- u% L" x! I2 V& D0 ?9 y7 Q% C& s
(setq y5 (+ y2 basr))
0 C9 W; j* \/ @3 ^9 s) c" z3 [ (setq p5 (list x2 y5))
) v" P: L2 z' U% U' T1 J (setq y55 (+ y2 r0))
9 R( ~8 e! R2 C+ ~( A" T. \3 h (setq p55 (list x2 y55))
; D# ?: S" x. Q2 |. r# ^( E, y+ _+ n" w (setq p88 (list (+ x2 2) (+ y5 2)))3 \0 m/ Y! Y' u1 ]
(setq a3 (/ (* pi 5) 4))
6 x+ a/ v y( D. X; R$ h& E+ t N (setq a4 (/ pi 4)). I3 U' p/ s0 t. j. }: e
(setq pz3 (polar p2 a3 (* orad 1.5)))0 {5 s- x6 i6 x/ r8 t4 _
(setq pz4 (polar p2 a4 (* orad 1.5)))
7 B* ^$ L5 d9 G2 D6 `# ` ~ (command "zoom" "w" pz3 pz4)( @ v. M7 l! j: @8 u
;
9 i+ p( P8 r3 i) r) j (setq clay (getvar "CLAYER"))( W1 x9 U# c* v) }
(setq sblip (getvar "BLIPMODE"))) I8 k! e6 S7 C/ O( m% q1 P, @' o
(setq ts (tblsearch "LAYER" "CEN"))
. N: Z% O7 i6 V* H (if (null ts)# H6 Z( B! C* g1 ~6 ?0 h# E
(progn
) s3 H4 l8 N: D' R" Y (prompt "\nCreating new layer - CEN. ")
9 r! G: _5 f0 T9 }. W (setvar "BLIPMODE" 0)7 b1 t$ U1 u% G; k* f1 D3 ]
(command "LAYER" "M" "CEN" "LT" "CENTER" "CEN" "C" "RED" "CEN" "")
0 N3 d8 k b9 a j j6 c8 B )
. \; N4 \7 q8 d* j+ k (progn5 R) v: s. f; j4 t# W/ j4 U
(if (> (cdr (assoc 70 ts)) 0) (command "LAYER" "T" "CEN" "ON" "CEN" "U" "CEN" ""))2 I6 ~3 N0 H! S) [
(command "LAYER" "S" "cen" "")
" |3 u/ c+ G2 x E% p% S8 g3 ] ) X- l, [/ K `) X
)
. K4 ]% q- |: c+ y+ N" R2 v (command "circle" p2 pitr)
, w' q& a8 x4 B0 W' o. i" p (setvar "BLIPMODE" sblip)
# `% a% c4 Z# [5 J8 l- D- W (command "LAYER" "S" clay "")
. v9 D6 e6 v% |;
3 B* i% e+ \, [2 E& U5 s (setq a1 (- (/ pi 2 ) 0.1))
# w9 }4 q( v* y2 U* E$ l1 C J (setq a2 (+ (/ pi 2) 0.1))6 x, T/ Z: N7 K- w4 [( x
(setq pz1 (polar p2 a1 basr))
# J( L' A- q P (setq pz2 (polar p2 a2 orad))
# T& `( x; {1 `' G" J/ Y (command "zoom" "w" pz1 pz2)1 ~$ o" {9 `5 }
(setq s (ssadd))" A2 }1 \) s/ Y$ z) k2 g l
(setq le (entlast))
* |: }2 ~# ^' y (setq test 0)2 a* z1 V3 A2 @
" e& u p, `6 k9 [, e' I (command "pline" p5)
: d/ ^; q/ `, `! L/ O (setq p (+ incr p ))
) E7 n# Q( ~0 e; S1 w' y (while (> pnts 0)4 y5 h' y4 K( i
(setq e1 (sin p))
# t* f; {4 v; ~6 m/ g. O( | (setq e2 (cos p))
- B8 Y% h0 o# q5 Z: [ (setq e (/ e1 e2))
! h: W! t7 p5 \ (setq j (- e p))5 @" t& a( t2 ~ N9 q8 Y* D1 u
(setq x1 (* (/ (sin j) (cos p)) basr))
5 Y7 I! f8 ~4 {2 S% w (setq y1 (* (/ (cos j) (cos p)) basr)) b7 r4 n( y8 s# u
(setq x3 (+ x2 x1))0 P* V5 W T5 E) h# Z
(setq y3 (+ y2 y1))
0 A0 }. p" O9 d/ }6 _# x (setq p3 (list x3 y3)), y) D0 ?$ f- I& e9 U
(command p3)
! b5 J5 y9 E: D2 o, b: j! ?! }" b (setq p (+ incr p))
* G$ i8 J+ F! u* P9 R: W- g (setq pnts (- pnts 1))* b8 N, s6 P$ \
(if (/= test 1)/ ]( M+ N" t/ H6 v8 o
(progn
0 A; L- u! A J$ j6 ]+ ?% q" E (setq hyp (sqrt (+ (expt x1 2) (expt y1 2))))9 D1 N/ c) ? Y
(if (> hyp pitr)
1 d) F% l3 f, K _9 e ~. h8 ^6 j (progn5 r* t3 B3 {8 [9 m) u+ |
(setq pint p3), S. V! y2 `+ e6 O) e6 l% Z* r
(setq test 1)
: R6 H5 J3 ]& Q8 J$ y9 ` )
* t+ N# W' _3 j) p )
3 m; ]0 @0 Z7 z3 {' a' @* A );endif
! ^! U$ s5 t P _+ p" |2 [ );endif5 i# h+ i7 Q* B% e6 p. K
)
. I5 }$ x! S0 t: |2 i (command "")5 t0 u% H9 u0 m! v/ C& K1 X
(setq L2 (ssget "L"))) o/ E( O5 q8 T! T! |
(initget "Y y N n")5 I( }( |7 i7 P+ I$ B" E
(setq ans (getkword "\n Finish the gear ?:<Y> "))" {* Q: m- @/ Z0 o4 o) }
(if (/= ans "N")
$ K7 u$ g3 G! A0 }7 ~5 D9 A (progn8 f3 Q8 K# B& _/ F+ h# [; \2 I
(command "zoom" "w" pz1 pz2)" [% @& o4 [: S5 X" j4 Y
(setq p11 (osnap pint "inter"))$ F, t" y9 Z, e/ a
(setq ang (angle p2 p11))
$ l, H! s# V, ]# P( G% j (setq angi (- ang pang))
! m8 s9 d; @; c8 Y (setq p12 (polar p2 angi 1.0))
: a* `& z. s1 G; t( a;
# w5 X) ]0 A2 U; `2 } (if (< (* 0.94 numt (/ 1 diap)) (* h 2.0005))
0 q$ [. s' \- l3 [5 J7 I7 O (progn
8 U& v" o+ i6 L+ S9 ]5 b6 C( P& \ (if (< numt 42)
/ h3 g0 q% k0 ?. y; M& m6 E (progn
% R& i) _/ r" o+ Y X7 b (setq p56 (list x2 (+ y2 r0))) ]1 X: N' O0 U) p( N' K+ Q
(command "line" p56 p5 "")+ ]. x) \# o1 r. Z' o
(setq L33 (entlast))# U- p/ }$ T. w3 q
(command "zoom" "w" p77 p88)
5 |& U$ g7 c" N, U (command "mirror" L2 L33 "" p2 p12 ""), ]$ ~( N5 }3 ]* |% m* L' k* A
(setq adj1 (- angi (/ pi 2)))
I+ r: r9 I6 y, F (setq adj2 (- (/ pi 2)(* pang 4)))
- W( c; o1 N' ^9 A2 Q( d (setq p17 (polar p2 (+ angi adj1) r0))
3 i/ t( x0 F) |1 _ (setq p16 (polar p2 adj2 r0)): x2 Q! I D9 H& z' G
(command "arc" p16 "c" p2 p17)
/ Y, e) d* z& w7 D2 v6 F ) ;end progn
9 f9 O* f; r" d" b8 I+ J (progn+ Y1 B. O% o& `. v( s& N
(command "zoom" "w" p77 p88)
4 n3 J# h% S8 k0 f, j9 V (command "mirror" L2 "" p2 p12 ""): e) Q. s; `8 ^' }: r2 B6 b) }
(setq pL1 (entlast))
' `5 z( z$ K' X (setq adj1 (- angi (/ pi 2))), l O# u" m" W
(setq adj2 (- (/ pi 2)(* pang 4)))
# ]( A8 c" Z4 M2 [# F% }& Y& C3 ` (setq p17 (polar p2 (+ angi adj1) r0))
+ h0 J% x' L! S, Z: g (setq p16 (polar p2 adj2 r0))
$ s# N' ~* G5 R7 I5 t (if (> numt 101)0 U. } L# W0 R4 V. q- y
(command "arc" p17 "c" p2 p16)- k6 w" x1 s. t: u3 c, p) N" i
(command "arc" p16 "c" p2 p17))
4 G; r- A3 ^* _5 x7 K& ` (setq arc4 (entlast))
5 y- o" @) D1 E- a (setq p171 (polar p17 0.7854 (/ 0.4 diap)))) M5 O3 I; M' R5 g) j) X( g1 g7 E: k3 @
(setq p172 (polar p17 3.9 (/ 0.4 diap)))7 K" K9 h. I/ e
(if (> numt 101) Y& u6 `& b; p5 R/ r' n' E
(setq p18 (polar p2 (+ angi adj1 ang0) r0))1 k, V7 b8 Q1 I
(setq p18 (polar p2 (+ adj2 ang0) r0)))$ @! l! u3 Q9 u9 ^2 p
(setq p181 (polar p18 2.3 (/ 0.4 diap)))
- P! t y& W4 ] (setq p182 (polar p18 5.5 (/ 0.4 diap)))
% s; s; B) c& B5 E8 }$ T: P (command "zoom" "w" p171 p172)
# A. O( A8 n( h. N (if (> numt 101)
; s4 X$ f& r, b0 b (command "extend" pL1 "" p16 "") 2 g+ z M( ~9 Y/ ?& Y
(command "extend" pL1 "" p17 ""))
: H5 {- j9 ? i8 ] (setq ang0 (/ (* ang0 180) pi))
9 y* m# Y* T9 {1 o8 p4 S3 K (command "rotate" arc4 "" p2 ang0)5 c5 n& b7 {* q% P3 F9 R
(command "zoom" "w" p181 p182), \( `5 F( W( c
(command "extend" L2 "" p18 "")) A7 a+ x, Q* e
(command "zoom" "w" pz1 pz2)
( y: [6 Q+ J5 v (command "trim" arc4 "" p5 "")
7 P6 s0 R8 A# M& Z (command "erase" pl1 "")
4 `0 V4 W2 k2 N (command "mirror" L2 "" p2 p12 "")
8 t: G4 i6 V/ | ) ;end progn
5 |2 R0 O7 N# c8 Y ) ;end if+ W( h) Y i. L
) ;end progn* j3 H3 S! v/ P8 t2 y
(progn
* W. z% ~" C8 Z. B+ t/ U, d8 o* t (setq ang12 (- (/ pi 2) (angle p2 p12))) # R" Y. c) W* {1 H! J
(setq ang57 (atan (/ r1 h)))
/ R z+ t7 Z2 n3 H s8 N (setq ang58 (- ang0 (* ang12 2) (* ang57 2)))
( E) D4 a4 G" n (setq ang577 (+ (/ pi 2) ang57))
/ |5 y% i! R. g+ O' T6 F* F& H+ U (setq ang588 (+ ang577 ang58))
0 @3 V- v1 i' Z0 t" U2 M (setq p57 (polar p2 ang577 (+ r1 r0)))
+ X4 ~4 S' }* p8 n (setq p577 (polar p2 ang577 r0))
$ l$ f( V- O2 G# u( \ (setq p588 (polar p2 ang588 r0)) % y" h) N1 u8 E E' ?
(setq p56 (list x2 (+ y2 h)))
- r3 X6 q4 `. h4 K3 b (command "arc" p577 "c" p57 p56)5 X+ d3 X* e+ \) B1 V2 P9 G$ [
(setq arc1 (entlast)) p9 x( r- S0 }. J5 ]5 S- B) M
(command "arc" p577 "c" p2 p588)
0 W6 g8 U$ [& G* o" K3 o) ^ (setq arc2 (entlast)) [% ~$ E) P, q R6 q/ k
(command "line" p56 p5 "")
2 C8 d3 ^* x: _ (setq L33 (entlast))
& {# {! p; v: \. M! R. w (command "zoom" "w" p77 p88): q/ g2 ^' \: \ D- c5 X" [$ n
(command "mirror" arc1 arc2 L2 L33 "" p2 p12 "")2 i! P L! \9 J
(command "erase" arc2 "")
7 ~6 c+ j- s9 e- L6 p ) ;end progn
O4 m" x& f8 _ ) ;end if
- p5 v8 Z& T A! o; * Q$ [& U- k4 @; Z+ c, F" v) i
(setq beta (angle p2 p3))
& |6 m% }. k _% i" o (setq ang2 (- (* angi 2) beta))! d' C, p" p, i( ]5 s9 K
(setq p15 (polar p2 ang2 orad))
4 m6 F2 q' D1 `5 l/ w (command "arc" p15 "c" p2 p3)
. _2 O% \$ {6 b# y (while (setq le (entnext le))
; w/ W) Z+ N2 N (ssadd le s)# E0 ^3 f0 i# O- [
)
+ v- I& a. V' A& x. p: ? (command "array" s "" "p" p2 numt "" "")
: S* _+ k) w, U1 W5 t- l( _ (setq q1 (nth 0 p2))
# b7 C8 C: j9 @2 L. M( q2 H" R (setq q2 (nth 1 p2))
3 V" Z7 y) f; R* s y8 y8 L2 H (setq q5 (+ q1 pitr 2))
+ C0 [- H. M8 Q, S( D3 v m( V (setq q6 (- q2 pitr 2))! w$ ]& ?7 W/ R# F- Q
(setq q3 (- q1 pitr 2))$ W6 L2 _% X {" X/ L: v
(setq q4 (+ q2 pitr 2))
6 v, @# j: ]% J$ m (setq q1 (list q5 q6))) Y2 v4 C2 K8 t8 `1 j& n
(setq q2 (list q3 q4))
1 O5 j/ O7 z6 ]! E5 j$ A. O (command "zoom" "w" q1 q2)
+ U1 V, B9 i8 O. j( w )
( y$ Z5 Y8 m- o) ^; i )- _: { g" ^0 L g# {
(setvar "pickbox" 5)
( x) }" ^( v$ |6 C (setvar "aperture" 5)
- ~0 J1 ?7 E" {! m# w/ c, U1 ~/ ^ (setvar "osmode" 37)
( J6 R( s3 N5 M- v
+ c) Q! R F* p' ~2 P" P (princ "Finish gear ")* O, n" E5 i$ p
(princ numt)) [' g% H+ g- c$ x! X
(princ "T")7 j) J6 ~' e. h. _4 V, T
(princ)
% d9 o, o7 q. e% }: L$ L( f )
, O6 f2 d0 Q; b4 s# J6 p& m
+ C) L5 E3 u. K |