#!/usr/bin/env perl $author = # # Rectilinear slide rule generating script # "Daisuke TOMINAGA, August 30, 2012"; # $credit = "\\copyright" . " " . "富永大介 (独立行政法人産業技術総合研究所 生命情報工学研究センター), 2012."; # tominaga@cbrc.jp # # How to use: # just run with perl. latex source script will be printed to STDOUT. # # License: # Everybody who want to use and distribute this script can do it under # the GNU General Public License # (GPL) version 3. # GPL v3 - http://www.gnu.org/licenses/gpl.html $DEBUG = 0; # print log numbers to a file 'tic.txt'. # 計算尺や要旨の全体的な寸法の定義, A4 に 240mm の尺を印刷することを想定 $L = 240; # 尺の全長, mm $BodyH = 60; # 計算尺の本体 (K, A, D 尺), $L+30 x 60mm $BodyL = $L+30; $PaperL = "271mm"; $PaperH = "176mm"; $BoxL = "270"; $BoxH = "170"; $h1 = 1; # いちばん小さい目盛りの高さ $h2 = 2; # $h3 = 3; # $h4 = 4; # $h5 = 5; # $h6 = 6; # いちばん高い目盛りの高さ # AB 尺の目盛り位置 $k = 0; for ($j = 1; $j < 2; $j += 0.05) { $ticAB[$k] = log($j); $mAB[$k++] = $j } for ($j = 2; $j < 5; $j += 0.1) { $ticAB[$k] = log($j); $mAB[$k++] = $j } for ($j = 5; $j < 10; $j += 0.2) { $ticAB[$k] = log($j); $mAB[$k++] = $j } for ($j = 10; $j < 20; $j += 0.5) { $ticAB[$k] = log($j); $mAB[$k++] = $j } for ($j = 20; $j < 50; $j += 1.0) { $ticAB[$k] = log($j); $mAB[$k++] = $j } for ($j = 50; $j < 100.1; $j += 2.0) { $ticAB[$k] = log($j); $mAB[$k++] = $j } for ($k = 0; $k < @ticAB; $k++) { $ticAB[$k] /= log(100) } # CD 尺の目盛り位置 $k = 0; for ($j = 1; $j < 2; $j += 0.02) { $ticCD[$k] = log($j); $mCD[$k++] = $j } for ($j = 2; $j < 4.99; $j += 0.05) { $ticCD[$k] = log($j); $mCD[$k++] = $j } for ($j = 5; $j < 10.04; $j += 0.10) { $ticCD[$k] = log($j); $mCD[$k++] = $j } for ($k = 0; $k < @ticCD; $k++) { $ticCD[$k] /= log(10) } # K 尺の目盛り位置 $k = 0; for ($j = 1; $j < 3; $j += 0.05) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 3; $j < 4.98; $j += 0.2 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 5; $j < 10; $j += 0.2 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 10; $j < 30; $j += 0.5 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 30; $j < 50; $j += 2.0 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 50; $j < 100; $j += 2.0 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 100; $j < 300; $j += 5.0 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 300; $j < 500; $j += 20.0 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($j = 500; $j < 1001; $j += 20.0 ) { $ticK[$k] = log($j); $mK[$k++] = $j } for ($k = 0; $k < @ticK; $k++) { $ticK[$k] /= log(1000) } $ticCD[0] = 0; $N = @ticCD; print "\\documentclass[a4,landscape]{jarticle}\n"; print "\\usepackage{graphicx,color}\n"; print "\\pagestyle{empty}\n"; print "\\setlength{\\oddsidemargin}{-20mm}\n"; print "\\setlength{\\topmargin}{-30mm}\n"; print "\\setlength{\\textwidth}{$PaperL}\n"; print "\\setlength{\\textheight}{$PaperH}\n"; print "\\newcommand{\\putc}[1]{\\setbox0=\\hbox{#1}\\kern-.5\\wd0{#1}}\n"; print "\\begin{document}\n"; print "\\begin{flushright}{\\small $author}\\end{flushright}\n"; print "\\definecolor{Gray03}{gray}{0.3}\n"; print "{\\setlength{\\unitlength}{1truemm}\n"; print " \\begin{picture}($BoxL,$BoxH)\n"; #print " \\put(0,0) {\\line( 0, 1){$BoxH}}\n"; # 原点は左下 #print " \\put(0,0) {\\line( 1, 0){$BoxL}}\n"; # 原点は左下 #print " \\put($BoxL,$BoxH){\\line( 0,-1){$BoxH}}\n"; # 原点は左下 #print " \\put($BoxL,$BoxH){\\line(-1, 0){$BoxL}}\n"; # 原点は左下 print " \\put(0,0) {\\line( 0, 1){$BodyH}}\n"; # 計算尺本体 print " \\put(0,0) {\\line( 1, 0){$BodyL}}\n"; # 計算尺本体 print " \\put($BodyL,$BodyH){\\line( 0,-1){$BodyH}}\n"; # 計算尺本体 print " \\put($BodyL,$BodyH){\\line(-1, 0){$BodyL}}\n"; # 計算尺本体 $BY1 = $SH1 + 3; $BX3 = $BodyL + 2; print " \\put($BX3,$BY1){\\rotatebox{90}{\\textbf{本体}}}\n"; $HK = 50; # K 尺 の横線の高さ, mm $HAB = 40; # A, B 尺共通の横線の高さ, mm $HCI = 26; # CI 尺 の横線の高さ, mm $HCD = 18; # C, D 尺共通の横線の高さ, mm $HDI = 10; # DI 尺 の横線の高さ, mm $OFF = 15; # 尺全体の本体の端からのオフセット $SVO = 65 - $HCD; # スライドの下側の描画領域内での高さが70mmになるようにする $SH = $HAB - $HCD; # スライドの高さ # 本体内の目盛りがのる線 print " \\put($OFF,$HK) {\\line(1,0){$L}}\n"; # K 尺 print " \\put($OFF,$HAB){\\line(1,0){$L}}\n"; # AB 尺 print " \\put($OFF,$HCD){\\line(1,0){$L}}\n"; # CD 尺 print " {\\color{red}\n"; print " \\put($OFF,$HDI){\\line(1,0){$L}}\n"; # DI 尺 print " }\n"; # スライド $HBS = $HAB + $SVO; $HIS = $HCI + $SVO; $HCS = $HCD + $SVO; $SH1 = $SVO + $HCD; print " \\put(0,$SH1){\\line(1,0){$BoxL}}\n"; # C 尺、スライド下端枠 print " \\put(0,$SH1){\\line(0,1){$SH}}\n"; # スライド両端の縦線 print " \\put($BoxL,$SH1){\\line(0,1){$SH}}\n"; # スライド両端の縦線 print " \\put(0,$HBS){\\line(1,0){$BoxL}}\n"; # B 尺、スライド上端枠 print " {\\color{red}\n"; print " \\put($OFF,$HIS){\\line(1,0){$L}}\n"; # CI 尺 print " }\n"; $BX1 = 5; $BX2 = $BoxL - 5; print " \\put($BX1,$SH1){\\line(0,1){$SH}}\n"; # 糊代 print " \\put($BX2,$SH1){\\line(0,1){$SH}}\n"; # 糊代 $BX1 = 1; $BX2 = $BoxL - 4; $BY1 = $SH1 + 3; $BX3 = $BoxL + 2; print " \\put($BX1,$BY1){\\rotatebox{90}{{\\small のり付け 1}}}\n"; print " \\put($BX2,$BY1){\\rotatebox{90}{{\\small のり付け 2}}}\n"; print " \\put($BX3,$BY1){\\rotatebox{90}{\\textbf{スライド}}}\n"; # 本体にスライドを通す穴 $BX1 = $OFF - 10; $BY1 = $HCD; $BW = 2; $BH = $HAB - $HCD; $BX2 = $BX1 + $BW; $BY2 = $BY1 + $BH; print " \\put($BX1,$BY1){\\line(1,0){$BW}}\n"; print " \\put($BX1,$BY1){\\line(0,1){$BH}}\n"; print " \\put($BX1,$BY2){\\line(1,0){$BW}}\n"; print " \\put($BX2,$BY1){\\line(0,1){$BH}}\n"; $BX1 = $BoxL - 10; $BY1 = $HCD; $BW = 2; $BH = $HAB - $HCD; $BX2 = $BX1 + $BW; $BY2 = $BY1 + $BH; print " \\put($BX1,$BY1){\\line(1,0){$BW}}\n"; print " \\put($BX1,$BY1){\\line(0,1){$BH}}\n"; print " \\put($BX1,$BY2){\\line(1,0){$BW}}\n"; print " \\put($BX2,$BY1){\\line(0,1){$BH}}\n"; # スライドに貼って延長するもの その1 $BX1 = 0; $BX2 = $BoxL; $BY1 = $HBS + 5; $BY2 = $BY1 + $BH; $BX3 = 5; print " \\put(0, $BY1){\\line(1,0){$BoxL}}\n"; print " \\put(0, $BY1){\\line(0,1){$SH}}\n"; print " \\put(0, $BY2){\\line(1,0){$BoxL}}\n"; print " \\put($BX2,$BY1){\\line(0,1){$SH}}\n"; print " \\put($BX3,$BY1){\\line(0,1){$SH}}\n"; # 糊代 $BX4 = $BX1 + 1; $BY4 = $BY1 + 3; print " \\put($BX4,$BY4){\\rotatebox{90}{{\\small のり付け 1}}}\n"; $BX5 = $BodyL + 2; $BY5 = $BY4; print " \\put($BX5,$BY5){\\rotatebox{90}{\\textbf{帯1}}}\n"; # スライドに貼って延長するもの その2 $BY1 = $BY2 + 5; $BY2 = $BY1 + $BH; print " \\put(0, $BY1){\\line(1,0){$BoxL}}\n"; print " \\put(0, $BY1){\\line(0,1){$SH}}\n"; print " \\put(0, $BY2){\\line(1,0){$BoxL}}\n"; print " \\put($BX2, $BY1){\\line(0,1){$SH}}\n"; print " \\put($BX3, $BY1){\\line(0,1){$SH}}\n"; # 糊代 $BY4 = $BY1 + 3; print " \\put($BX4,$BY4){\\rotatebox{90}{{\\small のり付け 2}}}\n"; $BX5 = $BodyL + 2; $BY5 = $BY4; print " \\put($BX5,$BY5){\\rotatebox{90}{\\textbf{帯2}}}\n"; # カーソル $CH0 = $BodyH + 1; # カーソルの高さ、本体高さ + 1mm、用紙上には横に置く $CH1 = $CH0 * 2; # カーソル部品としての高さ、糊代こみ $CH2 = $CH0 * 2 + 5; # カーソル部品としての高さ、糊代こみ $CW1 = 20; # カーソルの幅 $CX0 = $CH0; $CX1 = $CH1; $CX2 = $CH2; $CY1 = $BY2 + 5; $CY2 = $CY1 + $CW1; print " {\\color{red}\n"; print " \\put(0, $CY1){\\line(1,0){$CX2}}\n"; # カーソル下線、赤 print " \\put(0, $CY2){\\line(1,0){$CX2}}\n"; # カーソル上線、赤 print " }\n"; print " \\put(0, $CY1){\\line(0,1){$CW1}}\n"; print " {\\color{Gray03}\n"; print " \\put($CX0, $CY1){\\line(0,1){$CW1}}\n"; print " \\put($CX1, $CY1){\\line(0,1){$CW1}}\n"; print " }\n"; print " \\put($CX2, $CY1){\\line(0,1){$CW1}}\n"; $CX3 = $CX2 - 4; $CY3 = $CY1 + 3; print " \\put($CX3,$CY3){\\rotatebox{90}{{\\small のり付け 3}}}\n"; $CX4 = $CX3 + 8; $CY4 = $CY3; print " \\put($CX4,$CY4){\\rotatebox{90}{\\textbf{カーソル}}}\n"; # 目盛りの左側に、尺の名前を置く $LabOff1 = $OFF - 4; $LabOff2 = $OFF - 5; $LabHK = $HK; print " \\put($LabOff1, $LabHK){K}\n"; $LabABU = $HAB + 2; $LabABL = $HAB - 4 + $SVO; print " \\put($LabOff1, $LabABU){A}\n"; print " \\put($LabOff1, $LabABL){B}\n"; $LabCI = $HCI + $SVO; print " {\\color{red}\\put($LabOff2, $LabCI ){CI}}\n"; $LabCDU = $HCD + 2 + $SVO; $LabCDL = $HCD - 4; print " \\put($LabOff1, $LabCDU){C}\n"; print " \\put($LabOff1, $LabCDL){D}\n"; $LabDI = $HDI - 3; print " {\\color{red}\\put($LabOff2, $LabDI ){DI}}\n"; if ($DEBUG) { open(NUM, ">tic.txt") } # K 尺の目盛りを描く for ($i = 0; $i < @ticK; $i++) { $x = $ticK[$i] * $L + $OFF; # 目盛りの横方向の座標 # もっとも小さな目盛りをセットしておいて、切りのいい数値のところを高くする $h = $h1; if ($mK[$i] < 2) { # 0.1, 0.5 刻みのところを大きく if (abs(int($mK[$i]*10 +0.5) - ($mK[$i] * 10))< 0.001) { $h = $h2 } if (abs(int($mK[$i]*2 +0.5) - ($mK[$i] * 2)) < 0.001) { $h = $h3 } } elsif ($mK[$i] < 5) { # 0.2, 1.0 刻みのところを大きく if (abs(int($mK[$i]*5 +0.5) - ($mK[$i] * 5)) < 0.001) { $h = $h2 } if (abs(int($mK[$i] +0.5) - $mK[$i]) < 0.001) { $h = $h3 } } elsif ($mK[$i] < 10) { # 0.5, 1.0 刻みのところを大きく if (abs(int($mK[$i]*2 +0.5) - ($mK[$i] * 2)) < 0.001) { $h = $h2 } if (abs(int($mK[$i] +0.5) - $mK[$i]) < 0.001) { $h = $h3 } } elsif ($mK[$i] < 20) { # 1.0, 5.0 刻みのところを大きく if (abs(int($mK[$i] +0.5) - $mK[$i]) < 0.001) { $h = $h2 } if (abs(int($mK[$i]/2 +0.5) - ($mK[$i] / 2)) < 0.001) { $h = $h3 } } elsif ($mK[$i] < 50) { # 2, 10 刻みのところを大きく if (abs(int($mK[$i]/2 +0.5) - ($mK[$i] / 2)) < 0.001) { $h = $h2 } if (abs(int($mK[$i]/10 +0.5) - ($mK[$i] /10)) < 0.001) { $h = $h3 } } elsif ($mK[$i] < 100) { # 5, 10 刻みのところを大きく if (abs(int($mK[$i]/5 +0.5) - ($mK[$i] / 5)) < 0.001) { $h = $h2 } if (abs(int($mK[$i]/10 +0.5) - ($mK[$i] /10)) < 0.001) { $h = $h3 } } elsif ($mK[$i] < 200) { # 10, 50 刻みのところを大きく if (abs(int($mK[$i]/10 +0.5) - ($mK[$i] /10)) < 0.001) { $h = $h2 } if (abs(int($mK[$i]/50 +0.5) - ($mK[$i] /50)) < 0.001) { $h = $h3 } } elsif ($mK[$i] < 500) {# 10, 50 刻みのところを大きく if (abs(int($mK[$i]/20 +0.5) - ($mK[$i] /20)) < 0.001) { $h = $h2 } if (abs(int($mK[$i]/100+0.5) - ($mK[$i]/100)) < 0.001) { $h = $h3 } } else { # 50,100 刻みのところを大きく if (abs(int($mK[$i]/50 +0.5) - ($mK[$i] /50)) < 0.001) { $h = $h2 } if (abs(int($mK[$i]/100+0.5) - ($mK[$i]/100)) < 0.001) { $h = $h3 } } # 目盛り出力 print "\\put($x, $HK){\\line(0, 1){$h}}\n"; # 数字を置く @nLab = (1,2,3,4,5,10,20,30,40,50,100,200,300,400,500,1000); if ($h == $h3) { if (($mK[$i] > 1.4) && ($mK[$i] < 1.6)) { $mK[$i] = 1.5 } else { $mK[$i] = int($mK[$i] + 0.5) } for ($j = 0; $j < @nLab; $j++) { if ($mK[$i] == $nLab[$j]) { $lab = $mK[$i]; #if ($lab =~ /[2345]/) { $lab =~ s/0//g } $LabHKn = $HK + $h4 + 1; print "\\put($x, $LabHKn){\\putc{$lab}}\n"; } } } } # A, B 尺の目盛りを描く for ($i = 0; $i < @ticAB; $i++) { $x = $ticAB[$i] * $L + $OFF; # 目盛りの横方向の座標 # もっとも小さな目盛りをセットしておいて、切りのいい数値のところを高くする $h = $h1; if ($mAB[$i] < 2) { # 0.05, 0.1 刻みのところを大きく if (abs(int($mAB[$i]*20 +0.5) - ($mAB[$i] * 20)) < 0.001) { $h = $h2 } if (abs(int($mAB[$i]*10 +0.5) - ($mAB[$i] * 10)) < 0.001) { $h = $h3 } } elsif ($mAB[$i] < 5) { # 0.1, 0.5 刻みのところを大きく if (abs(int($mAB[$i]*2 +0.5) - ($mAB[$i] * 2)) < 0.001) { $h = $h2 } if (abs(int($mAB[$i] +0.5) - ($mAB[$i] )) < 0.001) { $h = $h3 } } elsif ($mAB[$i] < 10) { # 0.5, 1.0 刻みのところを大きく if (abs(int($mAB[$i]*2 +0.5) - ($mAB[$i] * 2)) < 0.001) { $h = $h2 } if (abs(int($mAB[$i] +0.5) - ($mAB[$i] )) < 0.001) { $h = $h3 } } elsif ($mAB[$i] < 20) { # 1.0, 5.0 刻みのところを大きく if (abs(int($mAB[$i] +0.5) - ($mAB[$i] )) < 0.001) { $h = $h2 } if (abs(int($mAB[$i]/2 +0.5) - ($mAB[$i] / 2)) < 0.001) { $h = $h3 } } elsif ($mAB[$i] < 50) { # 5.0, 10 刻みのところを大きく if (abs(int($mAB[$i]/2 +0.5) - ($mAB[$i] / 2)) < 0.001) { $h = $h2 } if (abs(int($mAB[$i]/10 +0.5) - ($mAB[$i] / 10)) < 0.001) { $h = $h3 } } else { # 10, 50 刻みのところを大きく if (abs(int($mAB[$i]/10 +0.5) - ($mAB[$i] / 10)) < 0.001) { $h = $h2 } if (abs(int($mAB[$i]/50 +0.5) - ($mAB[$i] / 50)) < 0.001) { $h = $h3 } } # 目盛り出力 print "\\put($x, $HAB){\\line(0, 1){$h}}\n"; # A 尺 print "\\put($x, $HBS){\\line(0,-1){$h}}\n"; # B 尺 # 数字を置く @nLab = (1, 1.5, 2, 2.5, 3, 4, 5, 10, 20, 30, 40, 50, 100); if ($h == $h3) { for ($j = 0; $j < @nLab; $j++) { if (abs($mAB[$i] - $nLab[$j]) < 0.01) { $lab = $nLab[$j]; # if ($lab =~ /[2345]/) { $lab =~ s/0//g } $LabHABn = $HAB + $h4 + 1; print "\\put($x, $LabHABn){\\putc{$lab}}\n"; $LabHABn = $HBS - $h4 - 2; print "\\put($x, $LabHABn){\\putc{$lab}}\n"; } } } } # C, D 尺の目盛りを描く for ($i = 0; $i < @ticCD; $i++) { $x = $ticCD[$i] * $L + $OFF; # 目盛りの横方向の座標 $y = $L + 2 * $OFF - $x; # CI/DI 尺の目盛りの横方向の座標 if ($y < 0) { $y = 0 } # もっとも小さな目盛りをセットしておいて、切りのいい数値のところを高くする $h = $h1; if ($mCD[$i] < 2) { # 0.05, 0.1 刻みのところを大きく if (abs(int($mCD[$i]*10 +0.5) - ($mCD[$i] * 10)) < 0.001) { $h = $h2 } if (abs(int($mCD[$i]*2 +0.5) - ($mCD[$i] * 2 )) < 0.001) { $h = $h3 } } elsif ($mCD[$i] < 5) { # 0.1, 0.5, 1.0 刻みのところを大きく if (abs(int($mCD[$i]*10 +0.5) - ($mCD[$i] * 10)) < 0.001) { $h = $h2 } if (abs(int($mCD[$i]*2 +0.5) - ($mCD[$i] * 2)) < 0.001) { $h = $h3 } if (abs(int($mCD[$i] +0.5) - $mCD[$i]) < 0.001) { $h = $h3 } } else { # 0.5, 1.0 刻みのところを大きく if (abs(int($mCD[$i]*2 +0.5) - ($mCD[$i] * 2)) < 0.001) { $h = $h2 } if (abs(int($mCD[$i] +0.5) - $mCD[$i]) < 0.001) { $h = $h3 } } # 目盛り出力, C, D 尺 print "\\put($x, $HCS){\\line(0, 1){$h}}\n"; # C 尺 print "\\put($x, $HCD){\\line(0,-1){$h}}\n"; # D 尺 # 目盛り出力, CI, DI 尺は赤い線で描く print "{\\color{red}\n"; print "\\put($y, $HIS){\\line(0, 1){$h}}\n"; # CI 尺 print "\\put($y, $HDI){\\line(0,-1){$h}}\n"; # DI 尺 print "}\n"; # 数字出力 if (abs(int($mCD[$i]+0.5) - $mCD[$i]) < 0.001) { # 整数きざみ $n = int($mCD[$i]+0.5); # まず C, D 尺 $hc = $HCS + $h3 + 1; $hd = $HCD - $h3 - 3; print "\\put($x, $hc){\\putc{$n}}\n"; # C 尺 print "\\put($x, $hd){\\putc{$n}}\n"; # D 尺 # 次に CI, DI 尺 $hc = $HIS + $h3 + 1; $hd = $HDI - $h4 - 2; print "{\\put($y, $hc){\\putc{\\textcolor{red}{$n}}}}\n"; # CI 尺 print "{\\put($y, $hd){\\putc{\\textcolor{red}{$n}}}}\n"; # DI 尺 } elsif (abs(int($mCD[$i]*2+0.5) - ($mCD[$i] * 2)) < 0.001) { # 0.5 刻み if (int($mCD[$i]*2+0.5) < 5*2) { $n = (int($mCD[$i]*2+0.5))/2; $hc = $HCS + $h3 + 1; $hd = $HCD - $h3 - 3; print "\\put($x, $hc){\\putc{$n}}\n"; # C 尺 print "\\put($x, $hd){\\putc{$n}}\n"; # D 尺 $hc = $HIS + $h3 + 1; $hd = $HDI - $h4 - 2; print "{\\put($y, $hc){\\putc{\\textcolor{red}{$n}}}}\n"; # CI 尺 print "{\\put($y, $hd){\\putc{\\textcolor{red}{$n}}}}\n"; # DI 尺 } } } $PI = log(3.14159265358979323846264338327950288)/log(10); $x = $PI * $L + $OFF; # 3.14 $xi = $L - ($PI * $L) + $OFF; print "\\color{red}\\put($x, $HCD){\\line(0, 1){$h4}}\n"; # π の目盛り on C print "\\color{red}\\put($x, $HCD){\\line(0,-1){$h4}}\n"; # π の目盛り on D $xp = $x - 1; $xip = $xi - 1; $hh = $HCD + $h4*1.1; print "{\\color{red}\\put($xp, $hh){\$\\pi\$}}\n"; # on C $hh = $HCD - $h4*1.25; $xp = $x - 2; print "{\\color{red}\\put($xp, $hh){\$\\pi\$}}\n"; # on D # クレジットの印刷 $BX5 = $BX4 + 5; $BY5 = $BY4; print " \\put($BX5, $BY5){\\color{black}$credit}\n"; print " \\end{picture}\n"; print "}\n"; print "\\end{document}\n";