use nalgebra::Vector3;
use super::{bar, lines, MU0_OVER_4PI};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ClosedForm {
pub value: f64,
pub relative_error: f64,
}
pub fn rectangular_bar_self(length: f64, width: f64, height: f64) -> ClosedForm {
rectangular_bars([length; 2], [width; 2], [height; 2], [0.0; 3])
}
pub fn rectangular_bars(
length: [f64; 2],
width: [f64; 2],
height: [f64; 2],
offset: [f64; 3],
) -> ClosedForm {
let result = bar::bar_integral(
&bar::corner_differences(length[0], length[1], offset[0]),
&bar::corner_differences(width[0], width[1], offset[1]),
&bar::corner_differences(height[0], height[1], offset[2]),
);
let areas = width[0] * height[0] * width[1] * height[1];
ClosedForm {
value: MU0_OVER_4PI * result.value / areas,
relative_error: result.relative_error,
}
}
pub fn parallel_filaments(length: f64, distance: f64) -> f64 {
2.0 * MU0_OVER_4PI * (length * (length / distance).asinh() - length.hypot(distance) + distance)
}
pub fn parallel_filaments_offset(
l1: f64,
l2: f64,
axial_offset: f64,
distance: f64,
) -> Option<f64> {
lines::parallel(l1, l2, axial_offset, distance).map(|k| MU0_OVER_4PI * k)
}
pub fn inclined_filaments(a0: [f64; 3], a1: [f64; 3], b0: [f64; 3], b1: [f64; 3]) -> Option<f64> {
let [a0, a1, b0, b1] = [a0, a1, b0, b1].map(Vector3::from);
let cos = (a1 - a0).normalize().dot(&(b1 - b0).normalize());
lines::skew(a0, a1, b0, b1, super::neumann::PARALLEL_SIN).map(|k| MU0_OVER_4PI * cos * k)
}