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>
impl<T> Vector3<T>
Sourcepub fn new(x: T, y: T, z: T) -> Selfwhere
T: Construct<T>,
pub fn new(x: T, y: T, z: T) -> Selfwhere
T: Construct<T>,
A clean way of making a Vector3 <x, y, z>
§Arguments
x
- The x direction scalar .0y
- The y direction scalar .1z
- The z direction scalar .2
Sourcepub fn normalize(&self, length: Option<T>) -> Vector3<T>
pub fn normalize(&self, length: Option<T>) -> Vector3<T>
Returns the Vector3
§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));
Sourcepub fn norm(&self) -> T
pub fn norm(&self) -> T
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);
Sourcepub fn unit_vector(&self) -> Self
pub fn unit_vector(&self) -> Self
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);
Sourcepub fn cross_product(a: Self, b: Self) -> Self
pub fn cross_product(a: Self, b: Self) -> Self
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 Vector4b
- 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));
Sourcepub fn dot_product(a: Self, b: Self) -> T
pub fn dot_product(a: Self, b: Self) -> T
Trait Implementations§
Source§impl<T> F32Fmt for Vector3<T>
impl<T> F32Fmt for Vector3<T>
type F32Fmt = Vector3<<T as F32Fmt>::F32Fmt>
fn intoF32Fmt(self) -> Self::F32Fmt
fn fromF32Fmt(f32_fmt: Self::F32Fmt) -> Self
fn cbrt(self) -> Self
fn f32_const_mul(self, constant: f32) -> Self
fn sin_mul(self, _mul_by: Self) -> Self
fn cos_mul(self, _mul_by: Self) -> Self
fn tan_mul(self, _mul_by: Self) -> Self
fn asin_mul(self, _mul_by: Self) -> Self
fn acos_mul(self, _mul_by: Self) -> Self
fn atan_mul(self, _mul_by: Self) -> Self
fn atan2_mul(self, _other: Self, _mul_by: Self) -> Self
fn sinh_mul(self, _mul_by: Self) -> Self
fn cosh_mul(self, _mul_by: Self) -> Self
fn tanh_mul(self, _mul_by: Self) -> Self
Source§impl<T> From<Quaternion<T>> for Vector3<T>where
T: Copy,
impl<T> From<Quaternion<T>> for Vector3<T>where
T: Copy,
Source§fn from(other: Quaternion<T>) -> Vector3<T>
fn from(other: Quaternion<T>) -> Vector3<T>
Converts to this type from the input type.
Source§impl<T> Mul<Vector3<T>> for Matrix3<T>
impl<T> Mul<Vector3<T>> for Matrix3<T>
Source§fn mul(self, rhs: Vector3<T>) -> Self::Output
fn mul(self, rhs: Vector3<T>) -> Self::Output
Matrix
[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));
impl<T> Construct<T> for Vector3<T>where
T: Construct<T>,
impl<T: Copy> Copy for Vector3<T>
impl<T> SqMatrix<T, Vector3<T>> for Matrix3<T>where
T: Construct<T>,
impl<T> StructuralPartialEq for Vector3<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more