#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/bike compare-tire () { local t1w=\$1 local t1bsd=\$2 local t1p=\$3 local t2w=\$4 local t2bsd=\$5 local t2p=\$6 local t1c=\$(circumference \$(( \$t1bsd / 2.0 )) ) local t2c=\$(circumference \$(( \$t2bsd / 2.0 )) ) local t1r=\$(( \$t1w / 2.0 )) local t2r=\$(( \$t2w / 2.0 )) local t1v=\$(( \$t1p * \$(cylinder \$t1r \$t1c) )) local t2v=\$(( \$t2p * \$(cylinder \$t2r \$t2c) )) printf "%.2f\n" \$(( \$t1v / 1.0 / \$t2v )) } # \$ compare-tire 28 622 85 28 622 85 # 1 # \$ compare-tire 28 622 85 23 622 100 # 1.26 # L = 2 (C) + (F/4 + R/4 + 1) # # * 1/8" = 0.125" # * 1/4" = 0.25" # * 3/8" = 0.375" # * 1/2" = 0.5" # * 5/8" = 0.625" # * 3/4" = 0.75" # * 7/8" = 0.875" chain-len () { local C=\$1 # chainstay len in inches, decimal form local F=\$2 # teeth on largest chainring local R=\$3 # teeth on largest sprocket local L # chain len in inches, decimal form L=\$(( 2*C + \${F}/4.0 + \${R}/4.0 + 1 )) local l # chain len in inches, fraction form l=\$(ths \$L) local c # chain len in cm c=\$(units -t "\$L inches" cm) echo "chain: \$c cm (\$l\")" } gear () { local wheel vared -p "wheel size: (BSD, e.g., 622) " -c wheel local rad=\$(( \$wheel / 2.0 )) local circ circ=\$(circumference \$rad) local chainrings vared -p "number of chainrings: " -c chainrings local sprockets vared -p "number of sprockets: " -c sprockets local teeth local -a cs for c in {1..\$chainrings}; do vared -p "chainring \$c: " -c teeth cs[\$c]=\$teeth unset teeth done local -a ss for s in {1..\$sprockets}; do vared -p "sprocket \$s: " -c teeth ss[\$s]=\$teeth unset teeth done local g for c in \$cs; do for s in \$ss; do g=\$(( (\$c*1.0) / \$s * \$circ )) echo \$g done done } circumference () { local r=\$1 local c=\$(( 2 * 3.1415 * \$r )) printf "%.2f\n" \$c } alias circle=circumference cylinder () { local r=\$1 local h=\$2 local v=\$(( 3.1415 * \$r * \$r * \$h )) printf "%.2f\n" \$v } radius () { local c=\$1 local r=\$(( \$c / (2*3.1415) )) printf "%.2f\n" \$r } mm () { local len=\$1 local to=inches local inches=\$(units -t -o '%.2f' "\${len} mm" \$to) echo \$inches \$to } preassure () { local quantity=\$1 local unit=\${2:l} local from="\${quantity} \${unit}" local to_1 local to_2 case \$unit in ("bar") to_1=kPa to_2=psi ;; ("psi") to_1=bar to_2=kPa ;; ("kpa") to_1=bar to_2=psi ;; esac echo "\${to_1}: \$(units -t -o '%.2f' \$from \$to_1)" echo "\${to_2}: \$(units -t -o '%.2f' \$from \$to_2)" }