Skip to content

Commit

Permalink
- add fov / focal length conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Mar 19, 2023
1 parent 9dc6829 commit a91217f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,21 @@ pub fn azimuth_altitude_to_xyz<T: Float + FloatOps<T>>(azimuth: T, altitude: T)
Vec3::<T>::new(x, z, y)
}

/// returns field of view converted from focal length with the specified aperture_width
pub fn focal_length_to_fov<T: Float + FloatOps<T> + Cast<T>>(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<T: Float + FloatOps<T> + Cast<T>>(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<T: Float + FloatOps<T>>(xyz: Vec3<T>) -> (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<T: Float, V: FloatOps<T>>(v: V) -> V {
V::cos(v)
Expand Down Expand Up @@ -377,11 +392,6 @@ pub fn log10<T: Float, V: FloatOps<T>>(v: V) -> V {
pub fn log<T: Float, V: FloatOps<T>>(v: V, base: T) -> V {
V::log(v, base)
}

/// returns (azimuth, altitude) converted from directional unit vector `xyz`
pub fn xyz_to_azimuth_altitude<T: Float + FloatOps<T>>(xyz: Vec3<T>) -> (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<T: Float + SignedNumberOps<T> + NumberOps<T> + FloatOps<T>>(points: &Vec<Vec2<T>>) -> Vec<Vec2<T>> {
Expand Down

0 comments on commit a91217f

Please sign in to comment.