From 681fdcf22956694877e0353452e586bc8164f0d7 Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Wed, 19 Jun 2024 21:39:05 +0300 Subject: [PATCH] `math::get_arbitrary_line_perpendicular` --- fyrox-math/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fyrox-math/src/lib.rs b/fyrox-math/src/lib.rs index 146c0aee9..e57513a1f 100644 --- a/fyrox-math/src/lib.rs +++ b/fyrox-math/src/lib.rs @@ -545,6 +545,21 @@ where closest_index } +#[inline] +pub fn get_arbitrary_line_perpendicular( + begin: Vector3, + end: Vector3, +) -> Option> { + let dir = (end - begin).try_normalize(f32::EPSILON)?; + for axis in [Vector3::x(), Vector3::y(), Vector3::z()] { + let perp = dir.cross(&axis); + if perp.norm_squared().ne(&0.0) { + return Some(perp); + } + } + None +} + /// Returns a tuple of (point index; triangle index) closest to the given point. #[inline] pub fn get_closest_point_triangle_set

(