From 5c28af3a53cf6006bba2ba40151f5ff41447fcbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Fri, 2 Feb 2018 12:26:31 +0100 Subject: [PATCH] Add 3d cross-product matrix construction from a vector. --- CHANGELOG.md | 3 +++ src/core/matrix.rs | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37a276ee..0c8fb210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). * `UnitQuaternion::scaled_rotation_between_axis` and `UnitQuaternion::rotation_between_axis` that take Unit vectors instead of Vector as arguments. + * `.cross_matrix()` returns the cross-product matrix of a given vector, i.e., + the matrix `M` such that for all vector `v` we have `M * v == + self.cross(&v)`. diff --git a/src/core/matrix.rs b/src/core/matrix.rs index 34f6b2db..55ed6d06 100644 --- a/src/core/matrix.rs +++ b/src/core/matrix.rs @@ -16,8 +16,8 @@ use abomonation::Abomonation; use alga::general::{Ring, Real}; -use core::{Scalar, DefaultAllocator, Unit, VectorN, MatrixMN}; -use core::dimension::{Dim, DimAdd, DimSum, U1, U2}; +use core::{Scalar, DefaultAllocator, Unit, VectorN, MatrixN, MatrixMN}; +use core::dimension::{Dim, DimAdd, DimSum, U1, U2, U3}; use core::constraint::{ShapeConstraint, SameNumberOfRows, SameNumberOfColumns, DimEq}; use core::iter::{MatrixIter, MatrixIterMut}; use core::allocator::{Allocator, SameShapeAllocator, SameShapeR, SameShapeC}; @@ -895,6 +895,17 @@ impl> Matrix { } } +impl> Vector + where DefaultAllocator: Allocator { + /// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`. + #[inline] + pub fn cross_matrix(&self) -> MatrixN { + MatrixN::::new(N::zero(), -self[2], self[1], + self[2], N::zero(), -self[0], + -self[1], self[0], N::zero()) + } +} + impl> Matrix { /// The smallest angle between two vectors. #[inline]