From 129b13411461cb69d96c253af4f8c7b473c72d7c Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 14 Jan 2024 11:09:51 -0800 Subject: [PATCH] Added util function --- crates/util/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/util/src/lib.rs b/crates/util/src/lib.rs index 16cf93c..87480ad 100644 --- a/crates/util/src/lib.rs +++ b/crates/util/src/lib.rs @@ -2,6 +2,8 @@ //! Various utilities +use nalgebra::Vector2; + pub mod constants; pub mod timing; @@ -9,3 +11,9 @@ pub mod timing; pub fn to_radians(degrees: f32) -> f32 { return (degrees / 360.0) * std::f32::consts::TAU; } + +/// Compute the clockwise angle between two vectors +/// Returns a value in [0, 2pi] +pub fn clockwise_angle(a: &Vector2, b: &Vector2) -> f32 { + (a.x * b.y - b.x * a.y).atan2(a.dot(&b)) +}