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.
§Panics
Panics if T, the vector’s datatype, cannot be converted to a f64.
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 const fn new(x: T, y: T, z: T) -> Self
pub const fn new(x: T, y: T, z: T) -> Self
Creates a new Vector3 with the specified coordinates.
§Examples
use vec3_rs::Vector3;
let vector3 = Vector3::new(1.0, 2.0, 3.0);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<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> PartialOrd for Vector3<T>where
T: Vector3Coordinate + Float,
impl<T> PartialOrd for Vector3<T>where
T: Vector3Coordinate + Float,
Source§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: Vector3<T>)
fn sub_assign(&mut self, rhs: Vector3<T>)
-= operation. Read more