From a91217f18218a8b036d594b1ee28b1677d93c459 Mon Sep 17 00:00:00 2001 From: polymonster Date: Sun, 19 Mar 2023 17:25:13 +0000 Subject: [PATCH] - add fov / focal length conversions --- src/lib.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c04f570..deeef7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -298,6 +298,21 @@ pub fn azimuth_altitude_to_xyz>(azimuth: T, altitude: T) Vec3::::new(x, z, y) } +/// returns field of view converted from focal length with the specified aperture_width +pub fn focal_length_to_fov + Cast>(focal_length: T, aperture_width: T) -> T { + T::two() * rad_to_deg(atan((aperture_width * T::from_f64(25.4)) / (T::two() * focal_length))) +} + +/// returns focal length converted field of view with the specified aperture_width +pub fn fov_to_focal_length + Cast>(fov: T, aperture_width: T) -> T { + (aperture_width * T::from_f64(25.4)) / (T::two() * tan(deg_to_rad(fov / T::two()))) +} + +/// returns (azimuth, altitude) converted from directional unit vector `xyz` +pub fn xyz_to_azimuth_altitude>(xyz: Vec3) -> (T, T) { + (T::atan2(xyz.y, xyz.x), T::atan2(xyz.z, sqrt(xyz.x * xyz.x + xyz.y * xyz.y))) +} + /// returns the cosine of `v` where the value `v` is in radians pub fn cos>(v: V) -> V { V::cos(v) @@ -377,11 +392,6 @@ pub fn log10>(v: V) -> V { pub fn log>(v: V, base: T) -> V { V::log(v, base) } - -/// returns (azimuth, altitude) converted from directional unit vector `xyz` -pub fn xyz_to_azimuth_altitude>(xyz: Vec3) -> (T, T) { - (T::atan2(xyz.y, xyz.x), T::atan2(xyz.z, sqrt(xyz.x * xyz.x + xyz.y * xyz.y))) -} /// returns a convex hull wound clockwise from point cloud `points` pub fn convex_hull_from_points + NumberOps + FloatOps>(points: &Vec>) -> Vec> {