pixalynx/pixal-nfc-card

This code defines React components representing specific electronic hardware components—namely, a 100-ohm SMD resistor, a surface-mount LED, and a chip with labeled pins—each modeled with detailed footprints, 3D CAD models, and manufacturer part information for PCB design.

Version
1.1.0
License
unset
Stars
0

lib/inductance.ts

import type { Pt } from "./coil"

const MU0_4PI = 1e-7

/** Antiderivative for the mutual inductance of two parallel filaments at spacing d (metres). */
const H = (u: number, d: number) => u * Math.asinh(u / d) - Math.hypot(u, d)

/**
 * Greenhouse-style estimate for an axis-aligned printed coil: the self
 * inductance of every flat segment plus the signed mutual inductance of every
 * parallel pair (perpendicular pairs contribute nothing). Lengths in mm,
 * result in henries. Ignores parasitic capacitance, the chip's input model and
 * the LED load, so treat it as a starting point for tuning, not a measurement.
 */
export function estimateInductance(path: Pt[], widthMm: number, copperMm = 0.035): number {
  const k = 1e-3
  const segs = path.slice(1).map((b, i) => [path[i], b] as const)
  const wt = (widthMm + copperMm) * k
  let L = 0
  for (let i = 0; i < segs.length; i++) {
    const [a, b] = segs[i]
    const l = Math.hypot(b.x - a.x, b.y - a.y) * k
    if (l === 0) continue
    L += 2 * MU0_4PI * l * (Math.log((2 * l) / wt) + 0.5 + (0.2235 * wt) / l)
    const horizA = a.y === b.y
    for (let j = i + 1; j < segs.length; j++) {
      const [c, e] = segs[j]
      if ((c.y === e.y) !== horizA) continue
      const d = (horizA ? Math.abs(a.y - c.y) : Math.abs(a.x - c.x)) * k
      if (d === 0) continue
      const [a1, a2] = horizA ? [a.x, b.x] : [a.y, b.y]
      const [b1, b2] = horizA ? [c.x, e.x] : [c.y, e.y]
      const sign = Math.sign(a2 - a1) * Math.sign(b2 - b1)
      const [lo1, hi1] = [Math.min(a1, a2) * k, Math.max(a1, a2) * k]
      const [lo2, hi2] = [Math.min(b1, b2) * k, Math.max(b1, b2) * k]
      L += 2 * sign * MU0_4PI * (H(hi1 - lo2, d) - H(hi1 - hi2, d) - H(lo1 - lo2, d) + H(lo1 - hi2, d))
    }
  }
  return L
}

export const resonanceHz = (L: number, C: number) => 1 / (2 * Math.PI * Math.sqrt(L * C))