Add 3d cross-product matrix construction from a vector.

This commit is contained in:
Sébastien Crozet 2018-02-02 12:26:31 +01:00
parent 3dc76caf7e
commit 5c28af3a53
2 changed files with 16 additions and 2 deletions

View File

@ -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)`.

View File

@ -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<N: Scalar + Ring, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
}
}
impl<N: Real, S: Storage<N, U3>> Vector<N, U3, S>
where DefaultAllocator: Allocator<N, U3> {
/// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`.
#[inline]
pub fn cross_matrix(&self) -> MatrixN<N, U3> {
MatrixN::<N, U3>::new(N::zero(), -self[2], self[1],
self[2], N::zero(), -self[0],
-self[1], self[0], N::zero())
}
}
impl<N: Real, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
/// The smallest angle between two vectors.
#[inline]