pub struct Vector3<T: Vector3Coordinate> { /* private fields */ }Expand description
Represents a vector in 3D space.
Implementations§
Source§impl<T: Vector3Coordinate> Vector3<T>
impl<T: Vector3Coordinate> Vector3<T>
Source§impl<T: Vector3Coordinate + Float> Vector3<T>
impl<T: Vector3Coordinate + Float> Vector3<T>
Sourcepub fn fuzzy_equal(&self, target: &Self, epsilon: T) -> bool
pub fn fuzzy_equal(&self, target: &Self, epsilon: T) -> bool
Checks if this vector is approximately equal to another vector within a given epsilon.
§Panics
Panics if epsilon is negative.
§Examples
use vec3_rs::Vector3;
let v1 = Vector3::new(0.1, 0.2, 0.3);
let v2 = Vector3::new(0.101, 0.199, 0.299);
let epsilon = 0.01;
let is_approx_equal = v1.fuzzy_equal(&v2, epsilon);
assert!(is_approx_equal)Sourcepub fn lerp(&self, target: &Self, alpha: T) -> Self
pub fn lerp(&self, target: &Self, alpha: T) -> Self
Linearly interpolates between this vector and another vector by a given ratio.
Sourcepub fn angle(&self, target: Self) -> T
pub fn angle(&self, target: Self) -> T
Computes the angle in radians between this vector and another vector.
Sourcepub fn angle_deg(&self, target: Self) -> T
pub fn angle_deg(&self, target: Self) -> T
Computes the angle in degrees between this vector and another vector.
Sourcepub fn distance(&self, target: Self) -> T
pub fn distance(&self, target: Self) -> T
Computes the distance between this vector and another vector.
Sourcepub fn reflect(&self, normal: Self) -> Self
pub fn reflect(&self, normal: Self) -> Self
Reflects this vector off a surface defined by a normal.
Sourcepub fn clamp(&self, min: T, max: T) -> Self
pub fn clamp(&self, min: T, max: T) -> Self
Returns a new vector with each component clamped to a given range.
Sourcepub fn rotated(&self, axis: Self, angle: T) -> Self
pub fn rotated(&self, axis: Self, angle: T) -> Self
Rotates the vector around an axis by a given angle in radians.
Sourcepub fn from_spherical(radius: T, polar: T, azimuth: T) -> Self
pub fn from_spherical(radius: T, polar: T, azimuth: T) -> Self
Creates a new Vector3 from spherical coordinates.
§Arguments
radius- The distance from the origin.polar- The polar angle (the angle from the z-axis, in radians).azimuth- The azimuth angle (the angle from the x-axis in the xy-plane, in radians).
Source§impl<T: Vector3Coordinate> Vector3<T>
impl<T: Vector3Coordinate> Vector3<T>
Sourcepub fn new<U: Into<T>>(x: U, y: U, z: U) -> Self
pub fn new<U: Into<T>>(x: U, y: U, z: U) -> Self
Creates a new Vector3 with the specified coordinates.
§Examples
type Vector3 = vec3_rs::Vector3<f64>;
let vector3 = Vector3::new(1.0, 2.0, 3.0);
let also_ok = Vector3::new(1, 2, 3);
assert_eq!(vector3, also_ok);
// can also be created from arrays and tuples
// but no automatic number conversion
let from_array = Vector3::from([1.0, 2.0, 3.0]);
let from_tuple = Vector3::from((1.0, 2.0, 3.0));
assert_eq!(vector3, from_array);
assert_eq!(vector3, from_tuple);
// conversion is fallible with unknown sized data types
let slice: &[f64] = [1.0, 2.0, 3.0].as_ref();
let from_slice = Vector3::try_from(slice).unwrap();
let from_vec = Vector3::try_from(vec![1.0, 2.0, 3.0]).unwrap();
assert_eq!(vector3, from_slice);
assert_eq!(vector3, from_vec);
Sourcepub fn dot(&self, target: Self) -> T
pub fn dot(&self, target: Self) -> T
Computes the dot product between this vector and another vector.
Sourcepub fn cross(&self, target: Self) -> Self
pub fn cross(&self, target: Self) -> Self
Computes the cross product between this vector and another vector.
Sourcepub fn max(&self, target: &Self) -> Self
pub fn max(&self, target: &Self) -> Self
Computes the component-wise maximum of this vector and another vector.
Trait Implementations§
Source§impl<T: Vector3Coordinate> Add for Vector3<T>
impl<T: Vector3Coordinate> Add for Vector3<T>
Source§impl<T: Vector3Coordinate> AddAssign for Vector3<T>
impl<T: Vector3Coordinate> AddAssign for Vector3<T>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<'de, T> Deserialize<'de> for Vector3<T>where
T: Deserialize<'de> + Vector3Coordinate,
impl<'de, T> Deserialize<'de> for Vector3<T>where
T: Deserialize<'de> + Vector3Coordinate,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: Vector3Coordinate> Display for Vector3<T>
impl<T: Vector3Coordinate> Display for Vector3<T>
Source§impl<T: Vector3Coordinate> Div<T> for Vector3<T>
impl<T: Vector3Coordinate> Div<T> for Vector3<T>
Source§impl<T: Vector3Coordinate> DivAssign<T> for Vector3<T>
impl<T: Vector3Coordinate> DivAssign<T> for Vector3<T>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl<T: Vector3Coordinate> Mul<T> for Vector3<T>
impl<T: Vector3Coordinate> Mul<T> for Vector3<T>
Source§impl<T: Vector3Coordinate> MulAssign<T> for Vector3<T>
impl<T: Vector3Coordinate> MulAssign<T> for Vector3<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl<T: Vector3Coordinate> Sub for Vector3<T>
impl<T: Vector3Coordinate> Sub for Vector3<T>
Source§impl<T: Vector3Coordinate> SubAssign for Vector3<T>
impl<T: Vector3Coordinate> SubAssign for Vector3<T>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl<T: Vector3Coordinate> TryFrom<Vec<T>> for Vector3<T>
Available on crate feature std only.
impl<T: Vector3Coordinate> TryFrom<Vec<T>> for Vector3<T>
std only.Source§impl<T: Vector3Coordinate> TryFrom<VecDeque<T>> for Vector3<T>
Available on crate feature std only.
impl<T: Vector3Coordinate> TryFrom<VecDeque<T>> for Vector3<T>
std only.