Struct Vector3

Source
pub struct Vector3<T>(pub T, pub T, pub T);
Expand description

A 3D vector

Tuple Fields§

§0: T§1: T§2: T

Implementations§

Source§

impl<T> Vector3<T>

Source

pub fn new(x: T, y: T, z: T) -> Self
where T: Construct<T>,

A clean way of making a Vector3 <x, y, z>

§Arguments
  • x - The x direction scalar .0
  • y - The y direction scalar .1
  • z - The z direction scalar .2
Source

pub fn normalize(&self, length: Option<T>) -> Vector3<T>
where T: Mul<T, Output = T> + Div<T, Output = T> + Add<T, Output = T> + F32Fmt + Copy,

Returns the Vector3 normalized to a given length

§Arguments
  • length - The length to normalize to. Default is 1
§Examples
use feo_math::linear_algebra::vector3::Vector3;
let vec = Vector3::new(2, 0, 0);
assert_eq!(vec.normalize(Some(5)), Vector3::new(5, 0, 0));
assert_eq!(vec.normalize(None), Vector3::new(1, 0, 0));
Source

pub fn norm(&self) -> T
where T: Add<T, Output = T> + Mul<T, Output = T> + F32Fmt + Copy,

Returns the magnitude, norm, or length of the vector denoted ||v||

§Examples
use feo_math::linear_algebra::vector3::Vector3;
let vec = Vector3::new(2, 0, 0);
assert_eq!(vec.norm(), 2);
Source

pub fn unit_vector(&self) -> Self
where Self: Div<T, Output = Self>, T: Add<T, Output = T> + Mul<T, Output = T> + F32Fmt + Copy,

Returns the unit vector of the vector denoted Uv

§Examples
use feo_math::linear_algebra::vector3::Vector3;
let v = Vector3::new(1.0, 2.0, 3.0);
let Uv = v.unit_vector();
assert_eq!(Uv.norm(), 1.0);
Source

pub fn cross_product(a: Self, b: Self) -> Self
where T: Mul<T, Output = T> + Sub<T, Output = T> + Copy,

Returns the cross product of 2 Vector4s denoted A x B A trick to know which direction the cross product vector will be pointing is the right hand rule

side view
         ^\ a x b (pointing up)
a _______|| _________ arm (you)
      ///_  
     | \__  
     |
     b (pointing left)

where your index finger is vector a pointing forwards along z your middle finger is vector b pointing left along x and your thumb is the cross product a x b pointing up If you want to think in standard camera space terms use the left hand rule and note that your index finger is pointing along -z

§Arguments
  • a - The first Vector4
  • b - The second Vector4
§Examples
use feo_math::linear_algebra::vector3::Vector3;
let a = Vector3(0, 0, -1);
let b = Vector3(-1, 0, 0);
assert_eq!(Vector3::cross_product(a, b), Vector3(0, 1, 0));
Source

pub fn dot_product(a: Self, b: Self) -> T
where T: Mul<T, Output = T> + Add<T, Output = T> + Copy,

Returns the dot product of 2 Vector4s denoted A . B

§Arguments
  • a - The first Vector4
  • b - The second Vector4
§Examples
use feo_math::linear_algebra::vector3::Vector3;
let a = Vector3(0, 0, -1);
let b = Vector3(-1, 0, 0);
assert_eq!(Vector3::dot_product(a, b), 0);

Trait Implementations§

Source§

impl<T> Add<T> for Vector3<T>
where T: Add<T, Output = T> + Copy,

Source§

fn add(self, rhs: T) -> Self::Output

Element wise addition

§Examples
use feo_math::linear_algebra::vector3::Vector3;
assert_eq!(Vector3(1, 3, 2) + 2, Vector3(3, 5, 4));
Source§

type Output = Vector3<T>

The resulting type after applying the + operator.
Source§

impl<T> Add for Vector3<T>
where T: Add<T, Output = T> + Copy,

Source§

fn add(self, rhs: Self) -> Self::Output

Vector

§Examples
use feo_math::linear_algebra::vector3::Vector3;
let vec = Vector3::new(1, 2, 3);
let expected = Vector3::new(2, 4, 6);
assert_eq!(vec + vec, expected);
Source§

type Output = Vector3<T>

The resulting type after applying the + operator.
Source§

impl<T: Clone> Clone for Vector3<T>

Source§

fn clone(&self) -> Vector3<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Vector3<T>
where T: Debug + Copy,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Div<T> for Vector3<T>
where T: Div<T, Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> Div for Vector3<T>
where T: Div<T, Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> F32Fmt for Vector3<T>
where T: F32Fmt + Copy,

Source§

fn sqrt(self) -> Self

Element wise square root

Source§

type F32Fmt = Vector3<<T as F32Fmt>::F32Fmt>

Source§

fn intoF32Fmt(self) -> Self::F32Fmt

Source§

fn fromF32Fmt(f32_fmt: Self::F32Fmt) -> Self

Source§

fn cbrt(self) -> Self

Source§

fn f32_const_mul(self, constant: f32) -> Self

Source§

fn sin_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn cos_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn tan_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn asin_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn acos_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn atan_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn atan2_mul(self, _other: Self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn sinh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn cosh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn tanh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

impl<T> From<[T; 3]> for Vector3<T>
where T: Copy,

Source§

fn from(other: [T; 3]) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Quaternion<T>> for Vector3<T>
where T: Copy,

Source§

fn from(other: Quaternion<T>) -> Vector3<T>

Converts to this type from the input type.
Source§

impl<T> From<Vector3<T>> for [T; 3]
where T: Copy,

Source§

fn from(other: Vector3<T>) -> [T; 3]

Converts to this type from the input type.
Source§

impl<T> From<Vector4<T>> for Vector3<T>
where T: Copy,

Source§

fn from(other: Vector4<T>) -> Vector3<T>

Converts to this type from the input type.
Source§

impl<T> Mul<T> for Vector3<T>
where T: Mul<T, Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Mul<Vector3<T>> for Matrix3<T>
where T: Add<T, Output = T> + Mul<T, Output = T> + Copy,

Source§

fn mul(self, rhs: Vector3<T>) -> Self::Output

Matrix * Vector3 = Vector3

[r0c0, r0c1, r0c2]   [x]   [x']
[r1c0, r1c1, r1c2] * [y] = [y']
[r2c0, r2c1, r2c2]   [z]   [z']
§Examples
use feo_math::linear_algebra::vector3::Vector3;
use feo_math::linear_algebra::matrix3::Matrix3;
let mat = Matrix3::new(
    [3, 2, 1],
    [1, 3, 2],
    [2, 1, 3]
);
let vec = Vector3::new(1, 3, 2);
assert_eq!(mat * vec, Vector3::new(11, 14, 11));
Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

impl<T> Mul for Vector3<T>
where T: Mul<T, Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T> Neg for Vector3<T>
where T: Neg<Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T> One for Vector3<T>
where T: One,

Source§

const ONE: Self

Source§

impl<T: PartialEq> PartialEq for Vector3<T>

Source§

fn eq(&self, other: &Vector3<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Rem<T> for Vector3<T>
where T: Rem<T, Output = T> + Copy,

Source§

fn rem(self, rhs: T) -> Self::Output

§Examples
use feo_math::linear_algebra::vector3;
Source§

type Output = Vector3<T>

The resulting type after applying the % operator.
Source§

impl<T> Rem for Vector3<T>
where T: Rem<T, Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl<T> SignOps for Vector3<T>

Source§

fn ptcopysign(self, _sign: Self) -> Self

Source§

fn ptsignum(self) -> i8

Source§

fn abs(self) -> Self

Source§

impl<T> Sub<T> for Vector3<T>
where T: Sub<T, Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Sub for Vector3<T>
where T: Sub<T, Output = T> + Copy,

Source§

type Output = Vector3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Two for Vector3<T>
where T: Two,

Source§

const TWO: Self

Source§

impl<T> Zero for Vector3<T>
where T: Zero,

Source§

const ZERO: Self

Source§

impl<T> Construct<T> for Vector3<T>
where T: Construct<T>,

Source§

impl<T: Copy> Copy for Vector3<T>

Source§

impl<T> SqMatrix<T, Vector3<T>> for Matrix3<T>
where T: Construct<T>,

Source§

impl<T> StructuralPartialEq for Vector3<T>

Source§

impl<T> Vector<T> for Vector3<T>
where T: Construct<T>,

Auto Trait Implementations§

§

impl<T> Freeze for Vector3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector3<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector3<T>
where T: Send,

§

impl<T> Sync for Vector3<T>
where T: Sync,

§

impl<T> Unpin for Vector3<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector3<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, A> Typed<T> for A
where T: Construct<A>,