鋼材硬さの相互計算を行う。入力はいろいろ選べる。引張強さは硬さじゃないけど参考に(単位はMPa)
・計算元の値は黄色
・範囲外はグレー
・入力セルがそもそも範囲外の場合は赤
というような出力を行う。
あくまでも参考である。
ソースを投稿しようとしたが、HTMLのタグなどが消えてしまう問題があり、投稿できない。どうしたらいいのだろうか。htmlのタグなどが結構消える。試行錯誤の結果、タグをタグと認識させないことが大事だとわかったので、 <>のタグを全角大文字にして投稿してみる。テキストエディタで<をに置換してからやってみるとできる、かな。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>硬さ換算テーブル</title>
<style>
body {
"MS Pゴシック", sans-serif;
}
table{
border-collapse: collapse;
}
table td{
padding: 0px;
border: 1px solid black;
width: 100px;
text-align: center;
}
input{
padding:2px;
width:78px;
border:none;
text-align: center;
font-size:100%;
}
</style>
<script>
var DataList=[
['HV',85,940,85,90,95,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,245,250,255,260,265,270,275,280,285,290,295,300,310,320,330,340,350,360,370,380,390,400,410,420,430,440,450,460,470,480,490,500,510,520,530,540,550,560,570,580,590,600,610,620,630,640,650,660,670,680,690,700,720,740,760,780,800,820,840,860,880,900,920,940],
['HRA',60.7,85.6,,,,,,,,,,,,,,,,,,60.7,61.2,61.6,62,62.4,62.7,63.1,63.5,63.8,64.2,64.5,64.8,65.2,65.8,66.4,67,67.6,68.1,68.7,69.2,69.8,70.3,70.8,71.4,71.8,72.3,72.8,73.3,73.6,74.1,74.5,74.9,75.3,75.7,76.1,76.4,76.7,77,77.4,77.8,78,78.4,78.6,78.9,79.2,79.5,79.8,80,80.3,80.6,80.8,81.1,81.3,81.8,82.2,82.6,83,83.4,83.8,84.1,84.4,84.7,85,85.3,85.6],
['HRB',41,110,41,48,52,56.2,62.3,66.7,71.2,75,78.7,81.7,85,87.1,89.5,91.5,93.4,95,96.7,98.1,98.8,99.5,100.25,101,101.5,102,102.75,103.5,104,104.5,105,105.5,106.25,107,107.5,108,108.5,109,109.5,110,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],
['HRC',0,68,,,,,,,,,,0,3,6,8.5,11,13.4,15.7,18,20.3,21.3,22.2,23.1,24,24.8,25.6,26.4,27.1,27.8,28.5,29.2,29.8,31,32.2,33.3,34.4,35.5,36.6,37.7,38.8,39.8,40.8,41.8,42.7,43.6,44.5,45.3,46.1,46.9,47.7,48.4,49.1,49.8,50.5,51.1,51.7,52.3,53,53.6,54.1,54.7,55.2,55.7,56.3,56.8,57.3,57.8,58.3,58.8,59.2,59.7,60.1,61,61.8,62.5,63.3,64,64.7,65.3,65.9,66.4,67,67.5,68],
['HRD',40.3,76.9,,,,,,,,,,,,,,,,,,40.3,41.1,41.7,42.2,43.1,43.7,44.3,44.9,45.3,46,46.5,47.1,47.5,48.4,49.4,50.2,51.1,51.9,52.8,53.6,54.4,55.2,56,56.8,57.5,58.2,58.8,59.4,60.1,60.7,61.3,61.6,62.2,62.9,63.5,63.9,64.4,64.8,65.4,65.8,66.2,66.7,67,67.5,67.9,68.3,68.7,69,69.4,69.8,70.1,70.5,70.8,71.5,72.1,72.6,73.3,73.8,74.3,74.8,75.3,75.7,76.1,76.5,76.9],
['HR15N',69.6,93.2,,,,,,,,,,,,,,,,,,69.6,70.1,70.6,71.1,71.6,72.1,72.6,73,73.4,73.8,74.2,74.6,74.9,75.6,76.2,76.8,77.4,78,78.6,79.2,79.8,80.3,81,81.4,81.8,82.3,82.8,83.2,83.6,83.9,84.3,84.7,85,85.4,85.7,86,86.3,86.6,86.9,87.2,87.5,87.8,88,88.2,88.5,88.8,89,89.2,89.5,89.7,89.8,90.1,90.3,90.7,91,91.2,91.5,91.8,92.1,92.3,92.5,92.7,92.9,93,93.2],
['HR30N',41.7,84.4,,,,,,,,,,,,,,,,,,41.7,42.5,43.4,44.2,45,45.7,46.4,47.2,47.8,48.8,49,49.7,50.2,51.3,52.3,53.6,54.4,55.4,56.4,57.4,58.4,59.3,60.2,61.1,61.9,62.7,63.5,64.3,64.9,65.7,66.4,67.1,67.7,68.3,69,69.5,70,70.5,71.2,71.7,72.1,72.7,73.2,73.6,74.2,74.6,75.1,75.5,75.9,76.4,76.8,77.2,77.6,78.4,79.1,79.7,80.4,81.1,81.7,82.2,82.7,83.1,83.6,84,84.4],
['HR45N',19.9,75.4,,,,,,,,,,,,,,,,,,19.9,21.1,22.2,23.2,24.3,25.2,26.2,27.1,27.9,28.7,29.5,30.4,31.1,32.5,33.9,35.2,36.5,37.8,39.1,40.4,41.7,42.9,44.1,45.3,46.4,47.4,48.4,49.4,50.4,51.3,52.2,53.1,53.9,54.7,55.6,56.2,57,57.8,58.6,59.3,59.9,60.5,61.2,61.7,62.4,63,63.5,64.1,64.7,65.3,65.7,66.2,66.7,67.7,68.6,69.4,70.2,71,71.8,72.2,73.1,73.6,74.2,74.8,75.4],
['HS',16.3,98,,,,16.3,17.6,19.4,20.8,22.3,23.8,25.2,26.6,28,29.4,30.7,32,33.4,34.7,36,36.6,37.2,37.9,38.5,39.1,39.7,40.4,41,41.6,42.2,42.8,43.4,44.6,45.7,46.9,48.1,49.2,50.3,51.4,52.5,53.6,54.6,55.7,56.7,57.8,58.8,59.8,60.8,61.8,62.8,63.7,64.7,65.6,66.6,67.5,68.4,69.3,70.2,71.1,72,72.8,73.7,74.5,75.4,76.2,77,77.8,78.6,79.4,80.2,81,81.8,83.3,84.8,86.2,87.6,89,90.4,91.7,93.1,94.3,95.6,96.8,98],
['HBW',71,767,71,86,90,95,105,114,124,133,143,152,162,171,181,190,200,209,219,228,233,238,243,247,252,256,261,265,270,275,280,284,294,303,313,322,331,341,350,360,369,378,388,397,405,415,425,433,442,452,460,471,478,488,497,507,517,525,535,545,554,564,573,582,591,601,611,620,630,638,647,656,670,684,698,710,722,733,745,757,767,,,],
['TensileStrength',283,2055,283,299,314,330,361,390,425,455,490,515,545,580,605,635,670,695,730,765,780,795,805,825,840,855,875,890,905,915,935,950,980,1005,1035,1070,1095,1130,1170,1205,1240,1290,1330,1370,1410,1460,1495,1530,1570,1620,1660,1705,1750,1795,1825,1860,1905,1950,1985,2020,2055,,,,,,,,,,,,,,,,,,,,,,,]
];
//データのフォーマットは
//指標の名前、最小値、最大値、データ列(85HV~940HVに対応した値)
//DataList[n][0]が名前、DataList[n][1]が最小値、Datalist[n][2]が最大値、DataList[n][3]~DataList[n][DataList[n].Length]がデータ
function calc(){
// console.log(document.form.InputData.length);
// console.log(document.form.Output.length);
var Input = document.form.InputData;
var ErrorMessage = ""; //エラー出たときの記録。これがブランクなら、処理を継続する?どうする?
var RnageOver = false;
//入力された硬さが何かを調べる。複数入力には対応していない。
var i;
var HardnessIndex=-1;
for(i=0; i<Input.length;i++){
if(Input[i].value!=""){
HardnessIndex=i;
break;
}
}
if(HardnessIndex==-1){
ErrorMessage += "データが入力されていません\n";
//ここで止めたいけど止められないので、else以下に続く
}
else{
//ビッカース硬さ以外だったら一旦ビッカース硬さを求める。
if(HardnessIndex!=0){
//硬さの範囲が適正か調べる
var InputValue = Input[HardnessIndex].value;
var LowLimit = DataList[HardnessIndex][1];
var HiLimit = DataList[HardnessIndex][2];
if((LowLimit-InputValue)*(HiLimit-InputValue)<=0){
//範囲が適正だったら
for(i=3;i<DataList[HardnessIndex].length-1;i++){
if((DataList[HardnessIndex][i]-InputValue)*(DataList[HardnessIndex][i+1]-InputValue)<=0){
DataIndex = i;
console.log("data "+DataIndex + " is between " + DataList[HardnessIndex][DataIndex] + " and "+DataList[HardnessIndex][DataIndex+1]);
console.log("HV is around "+ DataList[0][DataIndex] + " to " + DataList[0][DataIndex+1]);
break;
}
}
var HV = InteriorDivision(DataList[HardnessIndex][DataIndex],DataList[0][DataIndex],DataList[HardnessIndex][DataIndex+1],DataList[0][DataIndex+1],InputValue);
Input[0].value = HV
console.log(HV);
}
else{
//範囲外だったら
ErrorMessage += "入力値が範囲外です\n";
RnageOver = true;
;
}
}
//ビッカースかた各種硬さを求める
}
HV=Input[0].value;
//ここまでにビッカース硬さが求められているはず。
console.log(ErrorMessage);
var OutDataArray = new Array(DataList.length);
OutDataArray[0]=HV;
if(ErrorMessage==""){
for(i=1;i<DataList.length;i++){
//ビッカース以外も計算していく
for(var j=3;j<DataList[0].length-1;j++){
if((DataList[0][j]-HV)*(DataList[0][j+1]-HV)<=0){
OutDataArray[i] = InteriorDivision(DataList[0][j],DataList[i][j],DataList[0][j+1],DataList[i][j+1],HV);
break;
}
//データ探し
;
}
console.log(DataList[i][0] + "=" + OutDataArray[i]);
}
}
console.log(ErrorMessage);0
var table = document.getElementById("table");
var row = table.insertRow(-1);
var AddedCell;
AddedCell = row.insertCell(-1);
AddedCell.innerHTML = "換算結果";
for(i=0;i<11;i++){
AddedCell = row.insertCell(-1);
AddedCell.innerHTML = (OutDataArray[i]*1).toFixed(1);
Input[i].value = "";
if(i==HardnessIndex){
AddedCell.innerHTML = '<div style="background-color:#FFFFaa;width:100%">'+(OutDataArray[i]*1).toFixed(1)+'</div>';
if(RnageOver){
AddedCell.innerHTML = '<div style="background-color:red;width:100%">範囲外</div>';
}
}
if(AddedCell.innerHTML=="NaN"){
AddedCell.innerHTML = '<div style="background-color:gray;width:100%">範囲外</div>';
}
}
}
function InteriorDivision(x1,y1,x2,y2,x){
//内分点を求める関数。(x1,y2)から(x2,y2)に含まれる点xにおけるy座標を返す。計算上外分点でも返してしまうがとりあえず無視。
var s = (x-x1)/(x2-x1);
return s*y2+(1-s)*y1;
}
function enter(){
if(window.event.keyCode==13){
calc();
}
}
</script>
</head>
<body>
鋼材の硬さの換算を行います。入力の枠のいずれかに数字を入れてEnterキーまたは変換ボタンを押してください。<br>
換算結果は表の下に都度追加されていきます。<br>
<br>
<form name="form">
<table id="table">
<tbody>
<tr>
<td>硬さ</td>
<td>HV</td>
<td>HRA</td>
<td>HRB</td>
<td>HRC</td>
<td>HRD</td>
<td>HR15N</td>
<td>HR30N</td>
<td>HR45N</td>
<td>HS</td>
<td>HBW</td>
<td>引張強度</td>
</tr>
<tr style="font-size:small;">
<td>入出力範囲</td>
<td>85-940</td>
<td>61-85</td>
<td>41-110</td>
<td>10-68</td>
<td>41-76</td>
<td>70-93</td>
<td>42-84</td>
<td>20-75</td>
<td>17-98</td>
<td>71-767</td>
<td>283-2055MPa</td>
</tr>
<tr>
<td>入力</td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
<td><input type="text" name="InputData" onkeypress="enter();"></td>
</tr>
</tbody>
</table>
<button type="button" onclick="calc();">計算</button>
</form><br>
計算はSAE J 417に基づき、HBWや引張強度はネットのデータから借用しています。あくまでも上記は換算結果であり、目安にとどめてください。
</body>
</html>