#!/usr/bin/env perl $c = # # slide rule generating script # high precision cylindrical version with C and D scales # "Daisuke TOMINAGA, November 16, 2012"; # tominaga@cbrc.jp # # How to use: # just run with perl. latex source script will be written into STDOUT. # # License: # Anybody can use and distribute this script under GNU General Public License # (GPL) version 3. If you want some another license, please contact me. # GPL v3 - http://www.gnu.org/licenses/gpl.html # # History # November 16, 2012 # Change Length of the scale; 219mm -> 210.5mm # due to size (diameter) change of the CHIPSTAR container. # July 15, 2010 # Initial release use Math::Trig; # 円筒のサイズ [mm] $H = 10; # 一周したときの高さの変化 $R = 5; # 何周するか $D = 210.5/pi;# 直径、ココで指定するか、ちょっと下で円周を指定する # 目盛りの長さ [mm] $h1 = 1; # 小さい目盛りの高さ $h2 = 2; # $h3 = 3; # 中くらいの目盛りの高さ $h4 = 4; # $h5 = 5; # 高い目盛りの高さ # 尺の全長など [mm] if ($D > 0) { $CF = $D * pi } # 円周 else { $CF = 219 } $SINE = sqrt(( $H * $H)/(($CF * $CF) + ($H * $H))); $COSINE = sqrt(($CF * $CF)/(($CF * $CF) + ($H * $H))); $L0 = ($CF / $COSINE); # 一周分の尺の長さ。勾配があるので円周よりちょっと長い。 $L = ($CF / $COSINE) * $R; # 尺の総延長。回る回数倍 # 目盛りの尺上の位置を計算 # tic に目盛りの端からの位置 (全体の長さを 1 としたときの割合) # m にその目盛りの対数を取る前の値 (目盛りの上にかかれる数値) # j の増分がそのまま刻み幅になる $k = 0; for ($j=1; $j < 2; $j+=0.005) { $tic[$k] = log($j)/log(10); $m[$k++] = $j } for ($j=2; $j < 4; $j+=0.01) { $tic[$k] = log($j)/log(10); $m[$k++] = $j } for ($j=4; $j < 10.01; $j+=0.02) { $tic[$k] = log($j)/log(10); $m[$k++] = $j } $tic[0] = 0; $N = @tic; print "\\documentclass[landscape]{article}\n"; print "\\usepackage{graphicx,color}\n"; print "\\pagestyle{empty}\n"; print "\\setlength{\\topmargin}{-10mm}\n"; print "\\setlength{\\textheight}{171mm}\n"; print "\\setlength{\\textwidth}{220mm}\n"; print "\\setlength{\\oddsidemargin}{0mm}\n"; print "\\newcommand{\\putc}[1]{\\setbox0=\\hbox{#1}\\kern-.5\\wd0{#1}}\n"; print "\\begin{document}\n"; print "{\\setlength{\\unitlength}{1truemm}\n"; print " \\begin{picture}(200,170)\n"; $LB = 100; # picture 環境中でのC, D 尺共通の横線の高さ $HH = $H * ($R + 1); $LBh= $HH + $LB; print " \\put( 0, $LB){\\line(1,0){$CF}}\n"; # C 尺の切り取り枠 print " \\put( 0,$LBh){\\line(1,0){$CF}}\n"; print " \\put( 0, $LB){\\line(0,1){$HH}}\n"; print " \\put($CF, $LB){\\line(0,1){$HH}}\n"; $cpx = $CF - 5; $cpy = $LB + 1; print " \\put($cpx,$cpy){C}\n"; $cpx = 2; $cpy = $LBh - 4; print " \\put($cpx,$cpy){C}\n"; $HH = $HH + 15; $LBl = $LB - $HH; $cpx = 2; $cpy = $LB - 4; print " \\put($cpx,$cpy){D}\n"; $cpx = $CF - 5; $cpy = $LBl + 1; print " \\put($cpx,$cpy){D}\n"; print " \\put( 0,$LBl){\\line(1,0){$CF}}\n"; # D 尺の切り取り枠 print " \\put( 0,$LBl){\\line(0,1){$HH}}\n"; print " \\put($CF,$LBl){\\line(0,1){$HH}}\n"; $LBl = $LBl + 15; $HH = $HH - 15; for ($i = 0; $i < @tic; $i++) { # いままでに何周まわった? $round = int($tic[$i] * $R); # $tic[$i] / (1 / $R) を変形 # 目盛りの選択 if (abs(int($m[$i] +0.5) - $m[$i]) < 0.001) { $h = $h5 } elsif (abs(int($m[$i]*2 +0.5) - ($m[$i] * 2)) < 0.001) { $h = $h4 } elsif (abs(int($m[$i]*10+0.5) - ($m[$i] * 10)) < 0.001) { $h = $h3 } elsif (abs(int($m[$i]*20+0.5) - ($m[$i] * 20)) < 0.001) { $h = $h2 } else { $h = $h1 } # 目盛りをうつ座標の計算 $XC = ($tic[$i] - $round / $R) * $L * $COSINE; $YC = $tic[$i] * $L * $SINE + $LB; $XD = $XC; $YD = $YC - $LB + $LBl; # 目盛りの描画 print "\\put($XC, $YC){\\line(0, 1){$h}}\n"; # C 尺 print "\\put($XD, $YD){\\line(0,-1){$h}}\n"; # D 尺 # 数字出力 if (abs(int($m[$i]+0.5) - $m[$i]) < 0.001) { # 整数きざみ if (int($m[$i]+0.5) == 1) { $n = int($m[$i]+0.5); $xp = $XC + 1; $hh = $YC + $h4 + 2; print "\\put($xp, $hh){\\putc{$n}}\n"; # C 尺 $hh = $YD - $h4 - 2; print "\\put($xp, $hh){\\putc{$n}}\n"; # D 尺 } elsif (int($m[$i]+0.5) != 10) { $n = int($m[$i]+0.5); $xp = $XC; $hh = $YC + $h4 + 2; print "\\put($xp, $hh){\\putc{$n}}\n"; # C 尺 $hh = $YD - $h4 - 4; print "\\put($xp, $hh){\\putc{$n}}\n"; # D 尺 } } elsif (abs(int($m[$i]*2+0.5) - ($m[$i] * 2)) < 0.001) { # 0.5 刻み $n = (int($m[$i]*2+0.5))/2; if (abs(int($m[$i]*2+0.5)/2 - 2.5) < 0.001) { $xp = $XC - 2 } else { $xp = $XC } $hh = $YC + $h3 + 2; print "\\put($xp, $hh){\\putc{$n}}\n"; # C 尺 $hh = $YD - $h3 - 4; print "\\put($xp, $hh){\\putc{$n}}\n"; # D 尺 } elsif (abs(int($m[$i]*10+0.5) - ($m[$i] * 10)) < 0.001) { # 0.1 刻み if ($m[$i] > 3) { next } $n = (int($m[$i]*10+0.5))/10; $xp = $XC; $hh = $YC + $h2 + 2; print "\\put($xp, $hh){\\putc{$n}}\n"; # C 尺 $hh = $YD - $h2 - 4; print "\\put($xp, $hh){\\putc{$n}}\n"; # D 尺 } elsif (abs(int($m[$i]*20+0.5) - ($m[$i] * 20)) < 0.001) { # 0.05 刻み if ($m[$i] > 2) { next } $n = (int($m[$i]*20+0.5))/20; $xp = $XC; $hh = $YC + $h1 + 2; print "\\put($xp, $hh){\\putc{$n}}\n"; # C 尺 $hh = $YD - $h1 - 4; print "\\put($xp, $hh){\\putc{$n}}\n"; # D 尺 } } $P = log(pi)/log(10); $round = int($P * $R); # $tic[$i] / (1 / $R) を変形 $XC = ($P - $round / $R) * $L * $COSINE; $YC = $P * $L * $SINE + $LB; $XD = $XC; $YD = $YC - $LB + $LBl; print "\\color{red}\n"; print "\\put($XC, $YC){\\line(0, 1){$h4}}\n"; # π の目盛り on C print "\\put($XD, $YD){\\line(0,-1){$h4}}\n"; # π の目盛り on D $hh = $YC + $h4 + 1; print "{\\put($XC, $hh){\$\\pi\$}}\n"; # on C $hh = $YD - $h4 - 3; print "{\\put($XD, $hh){\$\\pi\$}}\n"; # on D print "\\color{black}\n"; $LBl = $LBl - 13; print " {\\small\\put(0,$LBl){Handmade cylindrical slide rule, $c}}\n"; print " \\end{picture}\n"; print "}\n"; print "\\clearpage\n"; print "{\\setlength{\\unitlength}{1truemm}\n"; $CH = $H * (2 * $R + 1); print " \\begin{picture}(200,170)\n"; print " \\put( 0, 0){\\line(1,0){$CF}}\n"; # カーソルの外枠 print " \\put( 0,$CH){\\line(1,0){$CF}}\n"; print " \\put( 0, 0){\\line(0,1){$CH}}\n"; # 糊代のとこ消したいときは消す print " \\color{red}\n"; print " \\put($CF, 0){\\line(0,1){$CH}}\n"; $CF6 = $CF / 6; print " \\put($CF6, 0){\\line(0,1){$CH}}\n"; $CF2 = $CF6 * 2; print " \\put($CF2, 0){\\line(0,1){$CH}}\n"; $CF2 = $CF6 * 3; print " \\put($CF2, 0){\\line(0,1){$CH}}\n"; $CF2 = $CF6 * 4; print " \\put($CF2, 0){\\line(0,1){$CH}}\n"; $CF2 = $CF6 * 5; print " \\put($CF2, 0){\\line(0,1){$CH}}\n"; print " \\end{picture}\n"; print "}\n"; print "\\end{document}\n";