[−][src]Struct linal::vec3::Vec3
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.
pub fn add(self, _rhs: Self) -> Self
[src]
impl AddAssign<Vec3> for Vec3
[src]
pub fn add_assign(&mut self, _rhs: Self)
[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.
pub fn div(self, _rhs: I) -> Self
[src]
impl<I: Into<f64>> DivAssign<I> for Vec3
[src]
pub fn div_assign(&mut self, _rhs: I)
[src]
impl FromStr for Vec3
[src]
type Err = ParseFloatError
The associated error which can be returned from parsing.
pub fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
impl Index<usize> for Vec3
[src]
type Output = f64
The returned type after indexing.
pub fn index(&self, index: usize) -> &Self::Output
[src]
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.
pub fn mul(self, _rhs: I) -> Self
[src]
impl Mul<Vec3> for Vec3
[src]
type Output = Self
The resulting type after applying the *
operator.
pub fn mul(self, _rhs: Self) -> Self
[src]
impl<I: Into<f64>> MulAssign<I> for Vec3
[src]
pub fn mul_assign(&mut self, _rhs: I)
[src]
impl MulAssign<Vec3> for Vec3
[src]
pub fn mul_assign(&mut self, _rhs: Self)
[src]
impl Neg for Vec3
[src]
impl PartialEq<Vec3> for Vec3
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl Sub<Vec3> for Vec3
[src]
type Output = Self
The resulting type after applying the -
operator.
pub fn sub(self, _rhs: Self) -> Self
[src]
impl SubAssign<Vec3> for Vec3
[src]
pub fn sub_assign(&mut self, _rhs: Self)
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,