#[repr(C)]pub struct Vector3<T> {
pub x: T,
pub y: T,
pub z: T,
}Expand description
A 3D vector with x, y, and z components.
§Examples
use rs_math3d::vector::{Vector3, CrossProduct};
let v1 = Vector3::new(1.0, 0.0, 0.0);
let v2 = Vector3::new(0.0, 1.0, 0.0);
let cross = Vector3::cross(&v1, &v2);
// Result is (0, 0, 1) - the z-axisFields§
§x: TX component.
y: TY component.
z: TZ component.
Implementations§
Trait Implementations§
Source§impl<T> CrossProduct for Vector3<T>where
T: Scalar,
impl<T> CrossProduct for Vector3<T>where
T: Scalar,
Source§fn cross(l: &Vector3<T>, r: &Vector3<T>) -> Vector3<T>
fn cross(l: &Vector3<T>, r: &Vector3<T>) -> Vector3<T>
Computes the cross product of two 3D vectors.
The cross product v × w produces a vector perpendicular to both v and w, following the right-hand rule.
§Properties
- Anti-commutative: v × w = -(w × v)
- Distributive: v × (w + u) = v × w + v × u
- v × v = 0
Source§impl<T: FloatScalar> FloatVector<T> for Vector3<T>
impl<T: FloatScalar> FloatVector<T> for Vector3<T>
Source§fn distance(l: &Self, r: &Self) -> T
fn distance(l: &Self, r: &Self) -> T
Computes the Euclidean distance between two vectors. Read more
Source§fn length_squared(&self) -> T
fn length_squared(&self) -> T
Computes the squared length (avoids a square root). Read more
Source§fn try_normalize(&self, epsilon: T) -> Option<Self>
fn try_normalize(&self, epsilon: T) -> Option<Self>
Returns a normalized vector or
None when the length is too small.Source§fn normalize_or_zero(&self, epsilon: T) -> Self
fn normalize_or_zero(&self, epsilon: T) -> Self
Returns a normalized vector or the zero vector when too small.
Source§fn normalize_with_inv_len(&self, inv_len: T) -> Self
fn normalize_with_inv_len(&self, inv_len: T) -> Self
Normalizes using a precomputed inverse length (e.g., from rsqrt).
Source§fn try_normalize_with_inv_len(
&self,
len_sq: T,
inv_len: T,
epsilon: T,
) -> Option<Self>
fn try_normalize_with_inv_len( &self, len_sq: T, inv_len: T, epsilon: T, ) -> Option<Self>
Normalizes with precomputed length squared and inverse length.
Source§impl<T: Scalar> Vector<T> for Vector3<T>
impl<T: Scalar> Vector<T> for Vector3<T>
impl<T: Copy> Copy for Vector3<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