Online Mechanical Engineering Stress-Strain Calculator
Calculate stress, strain, and Young's Modulus for a material under axial load.
Formula: E = σ / ε
`; resultsSection.classList.remove('hidden'); }; /** * Generates and triggers the download of a PDF report. */ const generatePdf = () => { if (!lastResult) { alert("Please perform a calculation first to generate a report."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFontSize(20); doc.text("Stress-Strain Calculation Report", 105, 20, { align: 'center' }); doc.setFontSize(12); doc.setTextColor(100); doc.text(`Date: ${new Date().toLocaleDateString()}`, 14, 30); // Input Parameters Table doc.autoTable({ startY: 35, head: [['Input Parameter', 'Value', 'Unit']], body: [ ['Force (F)', lastResult.inputs.force.toExponential(4), 'N'], ['Area (A)', lastResult.inputs.area.toExponential(4), 'm²'], ['Original Length (L₀)', lastResult.inputs.l0.toFixed(4), 'm'], ['Change in Length (ΔL)', lastResult.inputs.dl.toFixed(4), 'm'], ], theme: 'grid', headStyles: { fillColor: [51, 65, 85] }, // slate-700 }); // Results Table const modulusString = isFinite(lastResult.outputs.modulus) ? formatValue(lastResult.outputs.modulus, 'Pa') : 'Infinite (zero strain)'; doc.autoTable({ startY: doc.lastAutoTable.finalY + 10, head: [['Calculated Result', 'Value', 'Formula']], body: [ ['Stress (σ)', formatValue(lastResult.outputs.stress, 'Pa'), 'F / A'], ['Strain (ε)', lastResult.outputs.strain.toExponential(4), 'ΔL / L₀'], ["Young's Modulus (E)", modulusString, 'σ / ε'], ], theme: 'striped', headStyles: { fillColor: [71, 85, 105] }, // slate-600 }); doc.save('Stress_Strain_Report.pdf'); }; // --- EVENT LISTENERS --- calculateBtn.addEventListener('click', handleCalculation); downloadPdfBtn.addEventListener('click', generatePdf); });