[][src]Struct linal::vec3::Vec3

pub struct Vec3 {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

3D vector in cartesian coordinates

Fields

x: f64

component of vector

y: f64

component of vector

z: f64

component of vector

Implementations

impl Vec3[src]

pub fn new<I: Into<f64>>(x: I, y: I, z: I) -> Vec3[src]

Constructs a new Vec3.

Example

// create `Vec3` with int
let a = Vec3::new(10, 20, 30);
// create `Vec3` with float
let b = Vec3::new(3.5, 2.5, 1.5);
// Supported types implemented for trait Into (with convertion to f64)

pub fn from_spherical<I: Into<f64>>(r: I, theta: I, phi: I) -> Vec3[src]

Constructs a new Vec3 from spherical coordinates $(r, \theta, \phi)$.

Example

// calculation error
let eps = 1E-15;
// Create `Vec3` use spherical coordinates
let v = Vec3::from_spherical(2.0, PI / 2.0, PI / 2.0);
assert!(v.x < eps && v.y - 2.0 < eps && v.z < eps);

pub fn zero() -> Vec3[src]

Create a zero Vec3

Example

// create zero `Vec3`
let zero = Vec3::zero();
assert_eq!(zero, Vec3::new(0, 0, 0));

pub fn dot(self, rhs: Vec3) -> f64[src]

Scalar product

Example

let a = Vec3::new(1, 2, 3);
let b = Vec3::new(4, 5, 6);
// The scalar production of `a` by `b`
let r = a.dot(b);
assert_eq!(r, 32.0);

pub fn cross(self, rhs: Vec3) -> Self[src]

Cross product

Example

let a = Vec3::new(1, 2, 3);
let b = Vec3::new(2, 4, 6);
let c = Vec3::zero();
// Calculate cross production of `a` and `b` vectors
let d = a.cross(b);
assert_eq!(c, d);

pub fn len(self) -> f64[src]

Vector length

Example

let a = Vec3::new(4, 0, 0);
let e = Vec3::new(0, 0, 1);
let b = a.cross(e);
// Calculate vector length
let len1 = a.len();
let len2 = b.len();
assert!(a != b);
assert!(len1 == len2 && len1 == 4.0);

pub fn ort(self) -> Vec3[src]

Unary vector, co-directed with given

Example

let a = Vec3::new(2, 0, 0);
// Calculate unary vector from `a`
let b = a.ort();
assert_eq!(b, Vec3::new(1, 0, 0));

pub fn sqr(self) -> Vec3[src]

Squares of the vector coordinates

Example

let a = Vec3::new(2, 3, 4);
let b = Vec3::new(4, 9, 16);
// Calculate squre of `a`
let c = a.sqr();
assert_eq!(b, c);

pub fn sqrt(self) -> Vec3[src]

Square root of vector coordinates

Example

let a = Vec3::new(2, 3, 4);
let b = Vec3::new(4, 9, 16);
// Calculate squre root of `b`
let c = b.sqrt();
assert_eq!(a, c);

pub fn dual_basis(basis: (Vec3, Vec3, Vec3)) -> (Vec3, Vec3, Vec3)[src]

Constructs dual basis for given.

Dual basis $(\vec{b}_1, \vec{b}_2, \vec{b}_3)$ for basis $(\vec{a}_1, \vec{a}_2, \vec{a}_3)$ satisfies relation $$\vec{a}_i \cdot \vec{b}_j = \delta_{ij}$$

Example

let a1 = Vec3::new(2, 0, 0);
let a2 = Vec3::new(3, 4, 0);
let a3 = Vec3::new(3, 4, 5);

let (b1, b2, b3) = Vec3::dual_basis((a1, a2, a3));
assert_eq!(b1, Vec3::new(0.5, -0.375, 0.0));
assert_eq!(b2, Vec3::new(0.0, 0.25, -0.2));
assert_eq!(b3, Vec3::new(0.0, 0.0, 0.2));

Trait Implementations

impl Add<Vec3> for Vec3[src]

type Output = Self

The resulting type after applying the + operator.

impl AddAssign<Vec3> for Vec3[src]

impl Clone for Vec3[src]

impl Copy for Vec3[src]

impl Debug for Vec3[src]

impl Display for Vec3[src]

impl<I: Into<f64>> Div<I> for Vec3[src]

type Output = Self

The resulting type after applying the / operator.

impl<I: Into<f64>> DivAssign<I> for Vec3[src]

impl FromStr for Vec3[src]

type Err = ParseFloatError

The associated error which can be returned from parsing.

impl Index<usize> for Vec3[src]

type Output = f64

The returned type after indexing.

impl IndexMut<usize> for Vec3[src]

impl<I: Into<f64>> Mul<I> for Vec3[src]

type Output = Self

The resulting type after applying the * operator.

impl Mul<Vec3> for Vec3[src]

type Output = Self

The resulting type after applying the * operator.

impl<I: Into<f64>> MulAssign<I> for Vec3[src]

impl MulAssign<Vec3> for Vec3[src]

impl Neg for Vec3[src]

type Output = Self

The resulting type after applying the - operator.

impl PartialEq<Vec3> for Vec3[src]

impl Sub<Vec3> for Vec3[src]

type Output = Self

The resulting type after applying the - operator.

impl SubAssign<Vec3> for Vec3[src]

Auto Trait Implementations

impl RefUnwindSafe for Vec3

impl Send for Vec3

impl Sync for Vec3

impl Unpin for Vec3

impl UnwindSafe for Vec3

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.