[−][src]Struct linal::vec2::Vec2
2D vector in cartesian coordinates
Fields
x: f64
component of vector
y: f64
component of vector
Implementations
impl Vec2
[src]
pub fn new<I: Into<f64>>(x: I, y: I) -> Vec2
[src]
Constructs a new Vec2
.
Example
// create `Vec2` with int let a = Vec2::new(10, 20); // create `Vec2` with float let b = Vec2::new(3.5, 2.5); // Supported types implemented for trait Into (with convertion to f64)
pub fn from_polar<I: Into<f64>>(r: I, theta: I) -> Vec2
[src]
Constructs a new Vec2
from polar coordinates $(r, \theta)$.
Example
// calculation error let eps = 1E-15; // Create `Vec2` use polar coordinates let v = Vec2::from_polar(2.0, PI / 2.0); assert!(v.x < eps && v.y - 2.0 < eps);
pub fn zero() -> Vec2
[src]
Create a zero Vec2
Example
// create zero `Vec2` let zero = Vec2::zero(); assert_eq!(zero, Vec2::new(0, 0));
pub fn dot(self, rhs: Vec2) -> f64
[src]
Scalar product
Example
let a = Vec2::new(1, 2); let b = Vec2::new(3, 4); // The scalar production of `a` by `b` let r = a.dot(b); assert_eq!(r, 11.0);
pub fn cross(self) -> Vec2
[src]
Orthogonal vector
Example
let a = Vec2::new(2, 2); let b = Vec2::new(2, -2); // create orthogonal vector with same length // rotated in clockwise direction // y ^ // | // | // 2 - ...... /a // | // : // 1 - // : // -2 -1 | // : // -- | -- | -- 0 -- | -- | ----> // | \\ 1 : 2 x // - -1\\ : // | \\ : // - -2.....\b let c = a.cross(); assert_eq!(b, c);
pub fn area(self, rhs: Vec2) -> f64
[src]
Area of parallelogramm
Example
let a = Vec2::new(2, 0); let b = Vec2::new(1, 2); // Calculate the area of the parallelogram formed by the vectors // y ^ // | // | // 2 - b ......... // | /#########/ // 1 - /# area #/ // | /#########/ // 0 -- | -- a ----> // 1 2 x let area = a.area(b); assert_eq!(area, 4.0);
pub fn len(self) -> f64
[src]
Vector length
Example
let vec = Vec2::new(2, 0); // Calculate vector length let len1 = vec.len(); let len2 = (-vec.cross()).len(); assert!(len1 == len2 && len1 == 2.0);
pub fn ort(self) -> Vec2
[src]
Unary vector, co-directed with given
Example
let a = Vec2::new(2, 0); // Calculate unary vector from `a` let b = a.ort(); assert_eq!(b, Vec2::new(1, 0));
pub fn sqr(self) -> Vec2
[src]
Squares of the vector coordinates
Example
let a = Vec2::new(2, 3); let b = Vec2::new(4, 9); // Calculate square of `a` let c = a.sqr(); assert_eq!(b, c);
pub fn sqrt(self) -> Vec2
[src]
Square root of vector coordinates
Example
let a = Vec2::new(2, 3); let b = Vec2::new(4, 9); // Calculate squre root of `b` let c = b.sqrt(); assert_eq!(a, c);
pub fn dual_basis(basis: (Vec2, Vec2)) -> (Vec2, Vec2)
[src]
Constructs dual basis for given.
Dual basis $(\vec{b}_1, \vec{b}_2)$ for basis $(\vec{a}_1, \vec{a}_2)$ satisfies relation
$$\vec{a}_i \cdot \vec{b}_j = {\delta}_{ij}
$$
Example
let a1 = Vec2::new(2, 0); let a2 = Vec2::new(3, 4); let (b1, b2) = Vec2::dual_basis((a1, a2)); assert_eq!(b1, Vec2::new(0.5, -0.375)); assert_eq!(b2, Vec2::new(0.0, 0.25));
Trait Implementations
impl Add<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the +
operator.
pub fn add(self, _rhs: Self) -> Self
[src]
impl AddAssign<Vec2> for Vec2
[src]
pub fn add_assign(&mut self, _rhs: Self)
[src]
impl Clone for Vec2
[src]
impl Copy for Vec2
[src]
impl Debug for Vec2
[src]
impl Display for Vec2
[src]
impl<I: Into<f64>> Div<I> for Vec2
[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 Vec2
[src]
pub fn div_assign(&mut self, _rhs: I)
[src]
impl FromStr for Vec2
[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 Vec2
[src]
type Output = f64
The returned type after indexing.
pub fn index(&self, index: usize) -> &Self::Output
[src]
impl IndexMut<usize> for Vec2
[src]
impl<I: Into<f64>> Mul<I> for Vec2
[src]
type Output = Self
The resulting type after applying the *
operator.
pub fn mul(self, _rhs: I) -> Self
[src]
impl Mul<Vec2> for Vec2
[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 Vec2
[src]
pub fn mul_assign(&mut self, _rhs: I)
[src]
impl MulAssign<Vec2> for Vec2
[src]
pub fn mul_assign(&mut self, _rhs: Self)
[src]
impl Neg for Vec2
[src]
impl PartialEq<Vec2> for Vec2
[src]
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl Sub<Vec2> for Vec2
[src]
type Output = Self
The resulting type after applying the -
operator.
pub fn sub(self, _rhs: Self) -> Self
[src]
impl SubAssign<Vec2> for Vec2
[src]
pub fn sub_assign(&mut self, _rhs: Self)
[src]
Auto Trait Implementations
impl RefUnwindSafe for Vec2
impl Send for Vec2
impl Sync for Vec2
impl Unpin for Vec2
impl UnwindSafe for Vec2
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>,