use nalgebra::{Vector3, Vector6};
pub fn point_to_plane_row(point: &Vector3<f64>, normal: &Vector3<f64>) -> Vector6<f64> {
let moment = point.cross(normal);
Vector6::new(normal.x, normal.y, normal.z, moment.x, moment.y, moment.z)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::lie::Se3;
#[test]
fn row_matches_numeric_derivative() {
let point = Vector3::new(1.3, -0.7, 2.1);
let normal = Vector3::new(0.3, 0.5, -0.8).normalize();
let analytic = point_to_plane_row(&point, &normal);
const H: f64 = 1e-6;
for axis in 0..6 {
let mut delta = Vector6::zeros();
delta[axis] = H;
let forward = normal.dot(&(Se3::exp(&delta).transform_point(&point) - point));
let backward = normal.dot(&(Se3::exp(&(-delta)).transform_point(&point) - point));
let numeric = (forward - backward) / (2.0 * H);
assert!(
(analytic[axis] - numeric).abs() < 1e-8,
"axis {axis}: analytic {}, numeric {numeric}",
analytic[axis]
);
}
}
}