Vector

Type Alias Vector 

Source
pub type Vector<T, const N: usize> = Matrix<T, N, 1>;
Expand description

An alias for a Matrix with a single column

Aliased Type§

pub struct Vector<T, const N: usize> { /* private fields */ }

Implementations§

Source§

impl<T: Copy, const N: usize> Vector<T, N>

Operations for column vectors

Source

pub fn dot<R>(&self, rhs: &R) -> T
where for<'s> &'s Self: Mul<&'s R, Output = Self>, T: Sum<T>,

Compute the dot product of two vectors, otherwise known as the scalar product.

This is the sum of the elementwise product, or in math terms

$vec(a) * vec(b) = sum_(i=1)^n a_i b_i = a_1 b_1 + a_2 b_2 + … + a_n b_n$

for example, $[[1],[2],[3]] * [[4],[5],[6]] = (1 * 4) + (2 * 5) + (3 * 6) = 32$

For vectors in euclidean space, this has the property that it is equal to the magnitudes of the vectors times the cosine of the angle between them.

$vec(a) * vec(b) = |vec(a)| |vec(b)| cos(theta)$

this also gives it the special property that the dot product of a vector and itself is the square of its magnitude. You may recognize the 2D version as the pythagorean theorem.

see dot product on Wikipedia for more information.

Source

pub fn sqrmag(&self) -> T
where for<'s> &'s Self: Mul<&'s Self, Output = Self>, T: Sum<T>,

Source

pub fn mag(&self) -> T
where T: Sum<T> + Mul<T> + Real,

Source

pub fn normalized(&self) -> Option<Self>
where T: Sum<T> + Mul<T> + Real,

Source§

impl<T: Copy> Vector<T, 3>

Cross product operations for column vectors in $RR^3$

Source

pub fn cross_r<R: Copy>(&self, rhs: &Vector<R, 3>) -> Self
where T: NumOps<R> + NumOps,

Source

pub fn cross_l<R>(&self, rhs: &Vector<R, 3>) -> Vector<R, 3>
where R: NumOps<T> + NumOps + Copy,

Source§

impl<T: Copy, const N: usize> Vector<T, N>

Source

pub fn vec(data: [T; N]) -> Self

Create a vector from a 1D array. Note that vectors are always column vectors unless explicitly instantiated as row vectors

§Examples
// these are equivalent
assert_eq!(Vector::vec([1,2,3,4]), Matrix::mat([[1],[2],[3],[4]]));

Trait Implementations§

Source§

impl<T: Copy, const M: usize> From<[T; M]> for Vector<T, M>

Source§

fn from(data: [T; M]) -> Self

Converts to this type from the input type.
Source§

impl<T: Copy + Debug, const M: usize> Into<[T; M]> for Vector<T, M>

Source§

fn into(self) -> [T; M]

Converts this type into the (usually inferred) input type.