.PS # Mechanics.m4 # https://tex.stackexchange.com/questions/761731/tizk-and-circuitikz-how-to-put-frame-around-collection-of-commands-inside cct_init #_init(Mechanics) #nclude(tst.dim) divert(-1) Some simple electromechanical elements `barrier( R|L|U|D|degrees, keys ) Hatched [ ] block in $1 direction with a line on first side keys: wdth=expr; (dimen_/4) lgth=expr; (dimen_) line=attributes; (thick linethick*3/2) box=attributes; (e.g. dashed outline "color") hatchsep=expr; (4bp__) hatchspec=attributes; angle=degrees; (45) (relative to direction)' define(`barrier',`[ setdir_(`$1') pushkeys_(`$2', wdth:dimen_/4; lgth:dimen_; line:thick linethick*3/2:N; box:invis:N; hatchsep:4bp__; hatchspec::N; angle:45;) Box: hatchbox(wid=m4lgth; ht=m4wdth; box=m4box; hatchsep=m4hatchsep; angle=m4angle; boxdir=rp_ang*rtod_`'ifinstr(m4_dir_,`t',,+90)) Line: line by vec_(0,m4lgth) at Box+vec_(-m4wdth/2,0) m4line popdef(`m4wdth',`m4lgth',`m4line',`m4box',`m4hatchsep',`m4hatchspec',`m4angle') resetdir_ ]') `damper( linespec, keys ) Two-terminal element keys: wdth=expr; (dimen_/4) body width lgth=expr; (wdth*5/4) body=attributes; body outline and fill plunger=attributes;' define(`damper',`eleminit_(`$1') pushkeys_(`$2',`wdth:dimen_/4; lgth:(m4`'wdth)*5/4; body::N; plunger::N;') dnl if m4lgth > rp_len then { eleminit_(to rvec_(m4lgth,0)) } M4S: last line.start; M4E: last line.end; M4C: last line.c { line from M4S to (M4S+M4E)/2+vec_(m4lgth/6,0) {Body: [{ line thick linethick*3/2 by vec_(0,m4wdth*3/4) \ with .c at Here m4plunger } line from rvec_(-m4lgth*2/3,m4wdth/2) by vec_(m4lgth,0) then \ by vec_(0,-m4wdth) then by vec_(-m4lgth,0) m4body ] at rvec_(-m4lgth/6,0)} line from rvec_(m4lgth/3,0) to M4E} line invis to M4E popdef(`m4wdth',`m4lgth',`m4body',`m4plunger') ') `spring( linespec, keys ) keys: type=S|R|C; S=sharp, R=rounded, C=coiled wdth=expr; body width cycles=expr; lgth=expr; default cycles*wdth body=attributes; box body' define(`spring',`eleminit_(`$1') M4S: last line.start; M4E: last line.end; M4C: last line.c pushkeys_(`$2',`type:S:N; wdth:dimen_/5; cycles:4; lgth:(m4`'cycles)*(m4`'wdth)/2; body::N;')dnl if m4lgth > rp_len then { eleminit_(to rvec_(m4lgth,0)) } pushdef(`m4nN',`eval(2*m4cycles)') m4Rh=m4lgth/m4nN ifelse(m4type,S, `line to M4C+vec_(-m4nN*m4Rh/2,0); round [for_(2,m4nN,2,`line by vec_(m4Rh, m4wdth)ifelse(m4x,2,/2); round line by vec_(m4Rh,-m4wdth); round') line by vec_(m4Rh, m4wdth)/2; round] at M4C line from M4C+vec_(m4nN*m4Rh/2,0) to M4E', m4type,R, `{ line to rvec_((rp_len-m4lgth)/2,0) M4coil: [ S: Here; round; spline ifdpic(0.55) to rvec_(0,m4wdth/2) \ for_(1,m4cycles,1,`\ then to rvec_((m4x+0.3)*m4Rh*2, m4wdth/2) \ then to rvec_((m4x+0.3)*m4Rh*2,-m4wdth/2) \ then to rvec_((m4x-0.3)*m4Rh*2,-m4wdth/2) \ then to rvec_((m4x-0.3)*m4Rh*2, ifelse(m4x,eval(m4cycles),0,m4wdth/2))\')\ then to rvec_(m4lgth,0); round ] with .S at Here line from M4S+vec_((rp_len+m4lgth)/2,0) to M4E }') line invis from M4S to M4E') popdef(`m4type',`m4wdth',`m4cycles',`m4body',`m4lgth',`m4nN')dnl ') `coilspring( R|L|U|D|degrees, keys ) keys: wdth=expr; lgth=expr; cycles=expr; gauge=expr; wire thickness fcoil=attributes; front coils rcoil=attributes; rear coils' define(`coilspring',`[ setdir_(`$1',R) pushkeys_(`$2',`wdth:dimen_/3; lgth:dimen_; cycles:6; gauge:m4`'lgth/m4`'cycles/4; fcoil:shaded "white":N; rcoil:shaded lightgray:N;') cycles=int(m4cycles) define lightgray {rgbstring(0.83,0.83,0.83)} fpitch=(m4lgth-m4gauge)/cycles tn=vlength(fpitch/2,m4wdth-m4gauge) cang = atan2(fpitch/2,m4wdth-m4gauge)*rtod_ offset = m4gauge/2 + tn/2*fpitch/2/(m4wdth-m4gauge) for i=1 to cycles do { [setdir_(rp_ang*rtod_-cang) rotbox(m4gauge,tn+m4gauge,m4rcoil,r=m4gauge/2); resetdir_] \ at vec_(offset+(i-0.5)*fpitch,0)} rotbox(m4gauge,m4wdth,m4fcoil,r=m4gauge/2) at vec_(m4gauge/2,0) for i=1 to cycles do { [setdir_(rp_ang*rtod_+cang) rotbox(m4gauge,tn+m4gauge,m4fcoil,r=m4gauge/2); resetdir_] \ at vec_(offset+(i-1)*fpitch,0)} rotbox(m4gauge,m4wdth,m4fcoil,r=m4gauge/2) at vec_(m4lgth-m4gauge/2,0) popdef(`m4wdth',`m4cycles',`m4lgth',`m4gauge',`m4fcoil',`m4rcoil')dnl resetdir_ ] ') `cart( R|L|U|D|degrees, keys ) keys: wdth=expr; lgth=expr; body=attributes; wheelrad=expr; wheels=attributes; ' define(`cart',`[ setdir_(`$1',R) pushkeys_(`$2',`wdth:boxwid; ht:boxht; body::N; wheelrad:m4`'ht/5; wheels::N;') Box: rotbox(m4wdth,m4ht,m4body) LC: circle rad m4wheelrad fill_(1) m4wheels at Box.SW+vec_( m4wheelrad*5/4,0) RC: circle rad m4wheelrad fill_(1) m4wheels at Box.SE+vec_(-m4wheelrad*5/4,0) popdef(`m4wdth',`m4ht',`m4body',`m4wheelrad',`m4wheels') resetdir_ ] ') divert(0)dnl [ moveht /= 2 {damper; `"damper"' at last line.end ljust} move down_; right_ {barrier(D); `"barrier(D)"' with .w at (last "".w,Here) ljust} move down_; right_ {spring; "`spring'" at last line.end ljust} move down_; right_ {spring(,type=R); "`spring(,type=R)'" at last line.end ljust} {cart with .nw at last line.start+(0,-moveht/2) "`cart'" at last [].Box.e ljust} ] [ pivht = 1.2 pivwd = pivht*5/3 hingerad = 0.2*2/3 hingepinrad = 0.1*2/3 pivotrad = hingepinrad*3/2 pivotwid = pivotrad*2*2 pivotoffset = pivotrad*2 pratio = 3/2 BL: circle rad hingepinrad fill_(0) TL: circle rad hingepinrad fill_(0) at BL+(0,pivht) TR: circle rad hingepinrad fill_(0) at BL+(pivwd,pivht) BR: circle rad hingepinrad fill_(0) at BL+(pivwd,0) Pivot: circle rad pivotrad fill_(0) at 0.5 # pivot structure line down pivotoffset from Pivot+(-pivotwid/2,pivotoffset) arc to Pivot+(pivotwid/2,0) with .c at Pivot line up pivotoffset T: barrier(U,lgth=pivotwid*3/2;wdth=0.15;hatchsep=6pt__;line=thick 1.5; angle=-45) with .s at Pivot+(0,pivotoffset) thicklines_ # lower pivots hingeoffset = hingerad*2/3 line down hingeoffset from BL+(-hingerad,0) arc cw from BL+(-hingerad,0) to BL+( hingerad,0) with .c at BL line down hingeoffset line down hingeoffset from BR+(-hingerad,0) arc cw from BR+(-hingerad,0) to BR+( hingerad,0) with .c at BR line down hingeoffset # base # hatchbox(invis wid pivwd+4*hingerad ht 0.2,.1) \ # with .n at 0.5+(0,-hingeoffset) #thicklines_ barrier(D,lgth=pivwd+4*hingerad; wdth=0.2; hatchsep=6pt__;line=thick 1.5; angle=-45) with .n at 0.5+(0,-hingeoffset) `"Tuned-mass damper"' at last [].s below # mass dimensions widM = (BR.x-BL.x)*3/5 htM = pivht*2/3 hangerwid = widM/2 # mass M: box invis wid widM ht htM with .s at 0.5+(0,hingerad) dM = 0.1 define lightgray {rgbstring(0.83,0.83,0.83)} line from M.ne+(-dM,0) to M.nw+(dM,0) then to M.nw+(0,-dM) \ then to M.sw then to M.se then to M.ne+(0,-dM) then to M.ne+(-dM,0) \ shaded rgbstring(0.83,0.83,0.83) # horizontal arm endwid = hingerad arc ccw from TL+(-hingerad,0) to TL+( hingerad,0) with .c at TL line right Pivot.x-hangerwid/2-Here.x then down Here.y-M.n.y arc cw from TR+( hingerad,0) to TR+(-hingerad,0) with .c at TR line left Here.x-Pivot.x-hangerwid/2 then down Here.y-M.n.y line from TR+( hingerad,0) up endwid then to (Pivot.x+pivotwid/2,TR.y+endwid) line from TL+(-hingerad,0) up endwid then to (Pivot.x-pivotwid/2,TR.y+endwid) define rust {rgbstring(183/255,65/255,14/255)} S:coilspring(D,lgth=pivht*5/8;wdth=0.28;cycles=8;gauge=0.03; rcoil=shaded "gray"; fcoil=shaded rust) with .c at 0.5 shaftwid = hingepinrad*3/2 shaftchop = sqrt(hingerad^2-shaftwid^2/4) move to S.n+(shaftwid/2,0); line to (Here,TR) chop 0 chop shaftchop move to S.n+(-shaftwid/2,0); line to (Here,TR) chop 0 chop shaftchop move to S.s+(shaftwid/2,0); line to (Here,BR) chop 0 chop shaftchop move to S.s+(-shaftwid/2,0); line to (Here,BR) chop 0 chop shaftchop #D: box wid S.wid ht S.ht with .c at 0.5 D: box wid S.wid ht S.ht shaded "YellowOrange" with .c at 0.5 move to D.n+(shaftwid/2,0); line to (Here,TL) chop 0 chop shaftchop move to D.n+(-shaftwid/2,0); line to (Here,TL) chop 0 chop shaftchop move to D.s+(shaftwid/2,0); line to (Here,BL) chop 0 chop shaftchop move to D.s+(-shaftwid/2,0); line to (Here,BL) chop 0 chop shaftchop "{\sl mass}" at M "$m$" `"\shortstack{\sl spring\\$k$}"' at S.e ljust #"$k$" "\shortstack{\sl d{}ashpot\\$b$}" wid 34.1pt__ at D.w rjust "{\sl pivot}" at T.w rjust move to 0.5+(0.1,endwid/2) "$d$" at Here thinlines_ { arrow right 0.35 chop .06 } { arrow left 0.35 chop .06 } move to M.ne+(.1,0); move to (Here,(0.5)) { arrow to (Here,Pivot) chop 0.08 chop 0} { arrow to (Here,M) chop 0.08 chop 0} "$\ell$" "$x,\,f$" at T.e ljust arrow right 0.35 from last "".w+(19.5pt__,0) chop textoffset ] with .w at 1st [].e+(1.25,0) #howbox_ .PE