[]Struct lumol::types::Vector3D

pub struct Vector3D(_);

A 3-dimensional vector type

A Vector3D implement all the arithmetic operations:

let u = Vector3D::new(1.0, 2.0, 3.0);
let v = Vector3D::new(4.0, -2.0, 1.0);

// Indexing
assert_eq!(u[0], 1.0);
assert_eq!(u[1], 2.0);
assert_eq!(u[2], 3.0);

// Addition
let w = u + v;
assert_eq!(w, Vector3D::new(5.0, 0.0, 4.0));

// Subtraction
let w = u - v;
assert_eq!(w, Vector3D::new(-3.0, 4.0, 2.0));

// Negation
let w = -u;
assert_eq!(w, Vector3D::new(-1.0, -2.0, -3.0));

// Cross product
let w = u ^ v;
assert_eq!(w, Vector3D::new(8.0, 11.0, -10.0));

// Multiplication
let w = 2.0 * u;
assert_eq!(w, Vector3D::new(2.0, 4.0, 6.0));

let w = u * 3.0;
assert_eq!(w, Vector3D::new(3.0, 6.0, 9.0));

// Division
let w = u / 2.0;
assert_eq!(w, Vector3D::new(0.5, 1.0, 1.5));

// Dot product
let a = u * v;
assert_eq!(a, 3.0);

Methods

impl Vector3D

pub fn new(x: f64, y: f64, z: f64) -> Vector3D

Create a new Vector3D with components x, y, z

Examples

let vector = Vector3D::new(1.0, 0.0, -42.0);

assert_eq!(vector[0], 1.0);
assert_eq!(vector[1], 0.0);
assert_eq!(vector[2], -42.0);

pub fn zero() -> Vector3D

Create a new Vector3D with components 0, 0, 0

Examples

let vector = Vector3D::zero();
assert_eq!(vector[0], 0.0);
assert_eq!(vector[1], 0.0);
assert_eq!(vector[2], 0.0);

pub fn norm2(&self) -> f64

Return the squared euclidean norm of a Vector3D

Examples

let vec = Vector3D::new(1.0, 0.0, -4.0);
assert_eq!(vec.norm2(), 17.0);

pub fn norm(&self) -> f64

Return the euclidean norm of a Vector3D

Examples

let vec = Vector3D::new(1.0, 0.0, -4.0);
assert_eq!(vec.norm(), f64::sqrt(17.0));

pub fn normalized(&self) -> Vector3D

Normalize a Vector3D.

Examples

let vec = Vector3D::new(1.0, 0.0, -4.0);
let n = vec.normalized();
assert_eq!(n.norm(), 1.0);

pub fn tensorial(&self, other: &Vector3D) -> Matrix3

Tensorial product between vectors. The tensorial product between the vectors a and b creates a Matrix3 with component (i, j) equals to a[i] * b[j].

Examples

let a = Vector3D::new(1.0, 0.0, -4.0);
let b = Vector3D::new(1.0, 2.0, 3.0);
let matrix = Matrix3::new([
    [1.0, 2.0, 3.0],
    [0.0, 0.0, 0.0],
    [-4.0, -8.0, -12.0]
]);
assert_eq!(a.tensorial(&b), matrix);

pub fn min(&self) -> f64

Get the minimal value in this vector, using std::f64::min for comparison.

Examples

let vector = Vector3D::new(1.0, 0.0, -4.0);

assert_eq!(vector.min(), -4.0);

pub fn max(&self) -> f64

Get the maximal value in this vector, using std::f64::max for comparison.

Examples

let vector = Vector3D::new(1.0, 0.0, -4.0);

assert_eq!(vector.max(), 1.0);

Trait Implementations

impl<'a> Sub<Vector3D> for &'a Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a> Sub<&'a Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a mut Vector3D> for &'b mut Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a mut Vector3D> for &'b Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a> Sub<Vector3D> for &'a mut Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a Vector3D> for &'b Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl Sub<Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a> Sub<&'a mut Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a Vector3D> for &'b mut Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl Default for Vector3D

impl<'a, 'b> BitXor<&'a Vector3D> for &'b Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl BitXor<Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl<'a, 'b> BitXor<&'a Vector3D> for &'b mut Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl<'a> BitXor<Vector3D> for &'a Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl<'a, 'b> BitXor<&'a mut Vector3D> for &'b mut Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl<'a> BitXor<&'a Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl<'a, 'b> BitXor<&'a mut Vector3D> for &'b Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl<'a> BitXor<Vector3D> for &'a mut Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl<'a> BitXor<&'a mut Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the ^ operator.

impl From<[f64; 3]> for Vector3D

impl<'a> AddAssign<Vector3D> for Vector3D

impl<'a> AddAssign<&'a Vector3D> for Vector3D

impl<'a> AddAssign<&'a mut Vector3D> for Vector3D

impl<'a> MulAssign<f64> for Vector3D

impl<'a> MulAssign<&'a f64> for Vector3D

impl<'a> MulAssign<&'a mut f64> for Vector3D

impl PartialOrd<Vector3D> for Vector3D

impl<'a> Neg for &'a mut Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl Neg for Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a> Neg for &'a Vector3D

type Output = Vector3D

The resulting type after applying the - operator.

impl<'a> Mul<f64> for &'a Vector3D

type Output = Vector3D

The resulting type after applying the * operator.

impl Mul<Vector3D> for Vector3D

type Output = f64

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Vector3D> for &'b Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a> Mul<f64> for &'a mut Vector3D

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a mut Vector3D> for &'b Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a> Mul<&'a Vector3D> for Vector3D

type Output = f64

The resulting type after applying the * operator.

impl<'a> Mul<Vector3D> for &'a mut Vector3D

type Output = f64

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a mut Vector3D> for &'b Vector3D

type Output = f64

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a mut Vector3D> for &'b mut Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a> Mul<&'a Vector3D> for Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a> Mul<Vector3D> for &'a mut Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a mut Vector3D> for &'b mut Vector3D

type Output = f64

The resulting type after applying the * operator.

impl Mul<Vector3D> for Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Vector3D> for &'b Vector3D

type Output = f64

The resulting type after applying the * operator.

impl<'a> Mul<Vector3D> for &'a Vector3D

type Output = f64

The resulting type after applying the * operator.

impl Mul<f64> for Vector3D

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a> Mul<&'a mut Vector3D> for Vector3D

type Output = f64

The resulting type after applying the * operator.

impl<'a> Mul<Vector3D> for &'a Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Vector3D> for &'b mut Vector3D

type Output = f64

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a Vector3D> for &'b mut Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a> Mul<&'a mut Vector3D> for Matrix3

type Output = Vector3D

The resulting type after applying the * operator.

impl<'a> SubAssign<&'a Vector3D> for Vector3D

impl<'a> SubAssign<Vector3D> for Vector3D

impl<'a> SubAssign<&'a mut Vector3D> for Vector3D

impl Copy for Vector3D

impl Zero for Vector3D

impl Deref for Vector3D

type Target = [f64; 3]

The resulting type after dereferencing.

impl PartialEq<Vector3D> for Vector3D

impl DerefMut for Vector3D

impl<'a> DivAssign<&'a mut f64> for Vector3D

impl<'a> DivAssign<f64> for Vector3D

impl<'a> DivAssign<&'a f64> for Vector3D

impl Div<f64> for Vector3D

type Output = Vector3D

The resulting type after applying the / operator.

impl<'a> Div<f64> for &'a Vector3D

type Output = Vector3D

The resulting type after applying the / operator.

impl<'a> Div<f64> for &'a mut Vector3D

type Output = Vector3D

The resulting type after applying the / operator.

impl Clone for Vector3D

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<'a> Add<&'a Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl<'a> Add<Vector3D> for &'a Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a Vector3D> for &'b mut Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a mut Vector3D> for &'b mut Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl Add<Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl<'a> Add<Vector3D> for &'a mut Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl<'a> Add<&'a mut Vector3D> for Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a mut Vector3D> for &'b Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a Vector3D> for &'b Vector3D

type Output = Vector3D

The resulting type after applying the + operator.

impl Debug for Vector3D

Auto Trait Implementations

impl Send for Vector3D

impl Sync for Vector3D

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]