fix laser utility calculations

This commit is contained in:
makearmy 2026-07-10 17:22:41 -04:00
parent b59e8e54bb
commit 0855724cb0
5 changed files with 58 additions and 131 deletions

View file

@ -10,7 +10,7 @@ function num(v: string) {
return Number.isFinite(n) ? n : 0;
}
// Spot diameter (µm) ≈ 1.27 * M² * λ(µm) * f(mm) / D(mm)
// Focused Gaussian 1/e² diameter: d = 4 M² λ f / (π D).
export default function Page() {
const [lambdaNm, setLambdaNm] = useState("1064"); // nm (default fiber)
const [focalMm, setFocalMm] = useState("160"); // mm
@ -21,9 +21,9 @@ export default function Page() {
const lamUm = num(lambdaNm) / 1000; // convert nm -> µm
const f = num(focalMm);
const D = num(beamDm);
const M2 = Math.max(1, num(m2));
if (lamUm <= 0 || f <= 0 || D <= 0) return 0;
return 1.27 * M2 * lamUm * (f / D);
const M2 = num(m2);
if (lamUm <= 0 || f <= 0 || D <= 0 || M2 < 1) return 0;
return (4 / Math.PI) * M2 * lamUm * (f / D);
}, [lambdaNm, focalMm, beamDm, m2]);
const dMm = dUm / 1000;
@ -71,7 +71,7 @@ export default function Page() {
</CardHeader>
<CardContent className="grid gap-3 sm:grid-cols-2">
<div>
<div className="text-sm text-muted-foreground">Spot diameter</div>
<div className="text-sm text-muted-foreground">1/e² spot diameter</div>
<div className="text-lg">{dMm.toFixed(4)} mm</div>
<div className="text-xs text-muted-foreground">{dUm.toFixed(2)} µm</div>
</div>
@ -82,7 +82,10 @@ export default function Page() {
</div>
</CardContent>
</Card>
<p className="mt-4 text-xs leading-relaxed text-muted-foreground">
Gaussian-beam estimate: d = 4 M²λf/(πD), where D is the 1/e² beam diameter at the
lens. Real spots may be larger because of lens aberration, clipping, beam expansion, and focus error.
</p>
</ToolShell>
);
}