From bed47a82e706a13c22799fcf644753c69fdec6ad Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Sun, 7 Mar 2021 11:43:47 +0100 Subject: Projection friction impulses on an implicit cone instead of a pyramidal approximation. --- src/utils.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index e131b0a..4ed89f6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -107,6 +107,8 @@ pub trait WBasis: Sized { type Basis; /// Computes the vectors which, when combined with `self`, form an orthonormal basis. fn orthonormal_basis(self) -> Self::Basis; + /// Computes a vector orthogonal to `self` with a unit length (if `self` has a unit length). + fn orthonormal_vector(self) -> Self; } impl WBasis for Vector2 { @@ -114,6 +116,9 @@ impl WBasis for Vector2 { fn orthonormal_basis(self) -> [Vector2; 1] { [Vector2::new(-self.y, self.x)] } + fn orthonormal_vector(self) -> Vector2 { + Vector2::new(-self.y, self.x) + } } impl> WBasis for Vector3 { @@ -134,6 +139,13 @@ impl> WBasis for Vector3 { Vector3::new(b, sign + self.y * self.y * a, -self.y), ] } + + fn orthonormal_vector(self) -> Vector3 { + let sign = self.z.copy_sign_to(N::one()); + let a = -N::one() / (sign + self.z); + let b = self.x * self.y * a; + Vector3::new(b, sign + self.y * self.y * a, -self.y) + } } pub(crate) trait WVec: Sized { -- cgit