线上运行,可以直接打开:冯·米塞斯压力计算器(在线计算器)
作为程序员,没有合适的工具,就得手搓一个,PC端,移动端均可适用。废话不多说,直接上代码。
HTML:
<div class="calculator"><label for="sigmaX">主应力 σ₁ (MPa):</label> <input id="sigmaX" type="number" placeholder="输入主应力 σ₁"> <label for="sigmaY">主应力 σ₂ (MPa):</label> <input id="sigmaY" type="number" placeholder="输入主应力 σ₂"> <label for="sigmaZ">主应力 σ₃ (MPa):</label> <input id="sigmaZ" type="number" placeholder="输入主应力 σ₃"><button onclick="calculateVonMisesStress()">计算冯·米塞斯应力</button><div id="result" class="result">结果将在此显示</div></div>
JS:
function calculateVonMisesStress() {
const sigmaX = parseFloat(document.getElementById('sigmaX').value);
const sigmaY = parseFloat(document.getElementById('sigmaY').value);
const sigmaZ = parseFloat(document.getElementById('sigmaZ').value);
if (isNaN(sigmaX) || isNaN(sigmaY) || isNaN(sigmaZ)) {
document.getElementById('result').innerText = "请输入有效的数值。";
return;
}
// 冯·米塞斯应力公式: σv = √[0.5 * ((σ1 - σ2)^2 + (σ2 - σ3)^2 + (σ3 - σ1)^2)]
const vonMisesStress = Math.sqrt(
0.5 * ((sigmaX - sigmaY) ** 2 + (sigmaY - sigmaZ) ** 2 + (sigmaZ - sigmaX) ** 2)
);
document.getElementById('result').innerText = `冯·米塞斯应力: ${vonMisesStress.toFixed(2)} MPa`;
}
CSS:
.calculator {
width: 100%;
background-color: #333;
color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
label {
display: block;
margin-bottom: 10px;
font-size: 16px;
}
input, select {
width: 100%!important;
padding: 10px!important;
margin-bottom: 20px;
color: #000000;
border-radius: 5px;
border: 1px solid #555;
font-size: 16px!important;
background-color: #ffffff!important;
}
button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: orange;
}
.result {
font-size: 18px;
margin-top: 20px;
text-align: center;
}
option {
background-color: #ffffff;
}
p {
font-size: 18px;
margin-top: 5px!important;
}