/** * 거더 짝 받침 · 종단경사 S · 솔플레이트 열 두께 (결정 2026-11-06, RAG/받침방위각_솔플레이트검토.md §3, Q-SH1·4·8·9). * Pure. Used by src/core/sole-plate.ts (pier solplates, 2026-11-06) through src/core/bridge-pairs.ts. * * Frame: (E, N) in m as in the model (x = E, y = N). Azimuth: the model's 진북 방위각 (deg, clockwise from north), i.e. the * workbook CAD angle θ_CAD converted by 90 − θ_CAD. A girder at azimuth θ runs along (sin θ, cos θ). */ export interface PairBearing { no: number; x: number; y: number; /** z (EL m). Q-SH5: both ends on the 받침블럭 상면 basis; the pier z definition is still spec Q16. */ z: number; azimuthDeg: number; } export interface PairStructure { name: string; bearings: PairBearing[]; } /** Q-SH1 tolerances and the Q-SH4 azimuth check. */ export const PAIR_AZIMUTH_TOL_DEG = 0.1; export const PAIR_OFFSET_TOL_M = 0.1; export const AZIMUTH_CHECK_SEC = 10; export type PairWarning = 'WS01' | 'WS04'; export interface BearingPair { /** The bearing on structure k and its partner on structure k + 1 (structure order A1, P1 … Pn, A2). */ from: { structure: string; no: number }; to: { structure: string; no: number }; /** Horizontal distance (m), distance off the girder line of `from` (m), azimuth difference |θ_to − θ_from| (deg). */ distanceM: number; offsetM: number; azimuthDiffDeg: number; /** Direction from → to as an azimuth (deg), and its difference from each input azimuth (arc seconds). */ directionDeg: number; fromCheckSec: number; toCheckSec: number; /** S = (z_to − z_from) / distance × 100 (%), sign along the structure order (− = lower towards the later structure). */ slopePct: number; /** The structure on the higher end: the 오르막 쪽 where T1 sits for both bearings. */ uphill: string; warnings: PairWarning[]; } const DEG = Math.PI / 180; const angleDiffDeg = (a: number, b: number) => Math.abs(((a - b + 540) % 360) - 180); /** * Girder pairs between neighbouring structures (Q-SH1, Q-SH4). For each bearing b on structure k the candidates on k + 1 lie * ahead along b's azimuth, within 0.1° of its azimuth and 0.1 m of its girder line; the closest to the line is the pair * (WS04 when there were two or more). WS01 when either input azimuth is more than 10″ from the pair direction. */ export function girderPairs(structures: PairStructure[]): BearingPair[] { const pairs: BearingPair[] = []; for (let k = 0; k + 1 < structures.length; k++) { const here = structures[k], next = structures[k + 1]; for (const b of here.bearings) { const u = { e: Math.sin(b.azimuthDeg * DEG), n: Math.cos(b.azimuthDeg * DEG) }; const candidates = next.bearings.map((c) => { const d = { e: c.x - b.x, n: c.y - b.y }; return { c, along: d.e * u.e + d.n * u.n, offset: Math.abs(d.e * u.n - d.n * u.e), dAz: angleDiffDeg(c.azimuthDeg, b.azimuthDeg), d }; }).filter((t) => t.along > 0 && t.dAz <= PAIR_AZIMUTH_TOL_DEG && t.offset <= PAIR_OFFSET_TOL_M) .sort((p, q) => p.offset - q.offset); if (!candidates.length) continue; const best = candidates[0]; const distanceM = Math.hypot(best.d.e, best.d.n); const directionDeg = (Math.atan2(best.d.e, best.d.n) / DEG + 360) % 360; const fromCheckSec = angleDiffDeg(directionDeg, b.azimuthDeg) * 3600; const toCheckSec = angleDiffDeg(directionDeg, best.c.azimuthDeg) * 3600; const slopePct = ((best.c.z - b.z) / distanceM) * 100; const warnings: PairWarning[] = []; if (fromCheckSec > AZIMUTH_CHECK_SEC || toCheckSec > AZIMUTH_CHECK_SEC) warnings.push('WS01'); if (candidates.length > 1) warnings.push('WS04'); pairs.push({ from: { structure: here.name, no: b.no }, to: { structure: next.name, no: best.c.no }, distanceM, offsetM: best.offset, azimuthDiffDeg: best.dAz, directionDeg, fromCheckSec, toCheckSec, slopePct, uphill: best.c.z > b.z ? next.name : here.name, warnings, }); } } return pairs; } /** The pair a bearing belongs to, on either end; undefined when it has none (then WS03 with a fallback S, not done here). */ export function pairOf(pairs: BearingPair[], structure: string, no: number): BearingPair | undefined { return pairs.find((p) => (p.from.structure === structure && p.from.no === no) || (p.to.structure === structure && p.to.no === no)); } /** Smallest allowed thin-end thickness T_min (mm, Q-SH3). */ export const SOLE_T_MIN_MM = 22; /** Thickness one bearing needs: T_req = T_min + L·|S|/2 (L mm, S %). */ export function soleRequiredT(lengthMm: number, slopePct: number, tMinMm: number = SOLE_T_MIN_MM): number { return tMinMm + (lengthMm * Math.abs(slopePct)) / 200; } /** * Row thickness and end thicknesses (Q-SH8·9): T_row = max(T_min, ⌈max T_req⌉) over the row; per bearing * T1 = round(T_row + L·|S|/2) on the 오르막 쪽 and T2 = round(T_row − L·|S|/2) (≥ T_min by construction). */ export function soleRowThickness(items: { lengthMm: number; slopePct: number }[], tMinMm: number = SOLE_T_MIN_MM) { const T = Math.max(tMinMm, Math.ceil(Math.max(...items.map((i) => soleRequiredT(i.lengthMm, i.slopePct, tMinMm))) - 1e-9)); return { T, ends: items.map((i) => { const half = (i.lengthMm * Math.abs(i.slopePct)) / 200; return { T1: Math.round(T + half), T2: Math.round(T - half) }; }), }; }