Acoustic Scattering Calculator

Scatterer Type: ${data['Scatterer Type'].value}

`; resultHTML += `

Scattering Cross Section: ${data['Scattering Cross Section'].value} ${data['Scattering Cross Section'].unit}

`; resultHTML += `

Directivity Index: ${data['Directivity Index'].value} ${data['Directivity Index'].unit}

`; document.getElementById('result-values').innerHTML = resultHTML; // Populate table const tableBody = document.getElementById('result-table-body'); tableBody.innerHTML = ''; for (const [key, value] of Object.entries(data)) { const row = document.createElement('tr'); const cell1 = document.createElement('td'); cell1.textContent = key; row.appendChild(cell1); const cell2 = document.createElement('td'); cell2.textContent = value.value; row.appendChild(cell2); const cell3 = document.createElement('td'); cell3.textContent = value.unit; row.appendChild(cell3); tableBody.appendChild(row); } // Create visualization createVisualization(radius, data['Scatterer Type'].value); document.getElementById('results').style.display = 'block'; } function createVisualization(radius, type) { const viz = document.getElementById('visualization'); viz.innerHTML = ''; // Create scatterer const scatterer = document.createElement('div'); scatterer.className = 'scatterer'; // Adjust size based on scatterer type if (type === 'Sphere') { scatterer.style.width = `${Math.min(radius * 200, 150)}px`; scatterer.style.height = `${Math.min(radius * 200, 150)}px`; scatterer.style.borderRadius = '50%'; } else { scatterer.style.width = `${Math.min(radius * 200, 150)}px`; scatterer.style.height = '30px'; scatterer.style.borderRadius = '15px'; } viz.appendChild(scatterer); // Create waves for (let i = 0; i < 3; i++) { const wave = document.createElement('div'); wave.className = 'wave'; wave.style.animationDelay = `${i * 1}s`; viz.appendChild(wave); } } function generatePDF() { try { const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Title doc.setFontSize(18); doc.text('Acoustic Scattering Report', 105, 15, { align: 'center' }); // Date doc.setFontSize(10); doc.text(`Generated: ${new Date().toLocaleString()}`, 105, 22, { align: 'center' }); // Add results summary doc.setFontSize(12); const resultValues = document.getElementById('result-values').textContent; const lines = resultValues.split('\n').filter(line => line.trim() !== ''); let yPos = 40; lines.forEach(line => { doc.text(line.trim(), 14, yPos); yPos += 7; }); // Add table data yPos += 10; doc.setFontSize(14); doc.text('Detailed Parameters:', 14, yPos); yPos += 10; doc.setFontSize(12); const table = document.getElementById('result-table-body'); const rows = table.querySelectorAll('tr'); rows.forEach(row => { const cells = row.querySelectorAll('td'); doc.text(`${cells[0].textContent}: ${cells[1].textContent} ${cells[2].textContent}`, 20, yPos); yPos += 7; }); // Add note about visualization yPos += 10; doc.text('Note: The scattering visualization is available in the web version.', 14, yPos); // Save PDF doc.save('Acoustic_Scattering_Report.pdf'); } catch (error) { console.error('PDF generation error:', error); alert('PDF generation failed. Please try again or check your internet connection.'); } }
Scroll to Top