Add next batch of calculators and AWG support
This commit is contained in:
@@ -181,6 +181,74 @@ export function solve(
|
||||
out.val1 = (!isNaN(v2) && v2 > 0) ? fmt(10 * Math.log10(v2)) : '';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'awg': {
|
||||
const log92 = Math.log(92);
|
||||
const awgToDiameterMm = (g: number) => 0.127 * Math.pow(92, (36 - g) / 39);
|
||||
const diameterMmToAwg = (d: number) => 36 - 39 * Math.log(d / 0.127) / log92;
|
||||
const awgToCircularMils = (g: number) => 1000 * Math.pow(92, (36 - g) / 19.5);
|
||||
const circularMilsToAwg = (a: number) => 36 - 19.5 * Math.log(a / 1000) / log92;
|
||||
const awgToAreaMm2 = (g: number) => {
|
||||
const d = awgToDiameterMm(g);
|
||||
return Math.PI * Math.pow(d, 2) / 4;
|
||||
};
|
||||
const areaMm2ToAwg = (a: number) => {
|
||||
const d = Math.sqrt((4 * a) / Math.PI);
|
||||
return diameterMmToAwg(d);
|
||||
};
|
||||
|
||||
const slug = calc.slug;
|
||||
const formatAwg = (g: number) => isFinite(g) ? fmt(g) : '';
|
||||
|
||||
if (slug.includes('circular-mils')) {
|
||||
if (source === 1) {
|
||||
out.val2 = !isNaN(v1) ? fmt(awgToCircularMils(v1)) : '';
|
||||
} else {
|
||||
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(circularMilsToAwg(v2)) : '';
|
||||
}
|
||||
} else if (slug.includes('square-millimeters')) {
|
||||
if (source === 1) {
|
||||
out.val2 = !isNaN(v1) ? fmt(awgToAreaMm2(v1)) : '';
|
||||
} else {
|
||||
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(areaMm2ToAwg(v2)) : '';
|
||||
}
|
||||
} else {
|
||||
// diameter in millimeters
|
||||
if (source === 1) {
|
||||
out.val2 = !isNaN(v1) ? fmt(awgToDiameterMm(v1)) : '';
|
||||
} else {
|
||||
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(diameterMmToAwg(v2)) : '';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'brinell-rockwell': {
|
||||
// Approximate correlation for steels:
|
||||
// BHN = (1520000 - 4500 * HRC) / (100 - HRC)^2
|
||||
if (source === 1) {
|
||||
// Brinell to Rockwell C
|
||||
if (!isNaN(v1) && v1 > 0) {
|
||||
const a = v1;
|
||||
const disc = 4500 ** 2 + 4 * a * 1070000;
|
||||
const y = (4500 + Math.sqrt(disc)) / (2 * a);
|
||||
const hrc = 100 - y;
|
||||
out.val2 = fmt(hrc);
|
||||
} else {
|
||||
out.val2 = '';
|
||||
}
|
||||
} else {
|
||||
// Rockwell C to Brinell
|
||||
if (!isNaN(v2) && v2 < 100) {
|
||||
const h = v2;
|
||||
const bhn = (1520000 - 4500 * h) / Math.pow(100 - h, 2);
|
||||
out.val1 = fmt(bhn);
|
||||
} else {
|
||||
out.val1 = '';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
Reference in New Issue
Block a user