From c38ab65562e4fcb57d79838002c6923e98f5cab9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 29 Jul 2024 18:55:24 +0200 Subject: [PATCH] Add `Vector::angle_to` --- crates/fj-math/src/vector.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/fj-math/src/vector.rs b/crates/fj-math/src/vector.rs index 4e6c45273..5c08f6bd4 100644 --- a/crates/fj-math/src/vector.rs +++ b/crates/fj-math/src/vector.rs @@ -87,6 +87,11 @@ impl Vector { self.to_na().normalize().into() } + /// Compute the angle between this vector and another + pub fn angle_to(&self, other: &Self) -> Scalar { + (self.dot(other) / (self.magnitude() * other.magnitude())).acos() + } + /// Compute the dot product with another vector pub fn dot(&self, other: &Self) -> Scalar { self.to_na().dot(&other.to_na()).into()