pub struct Vector4 { /* private fields */ }Expand description
Represents a 4-dimensional vector with f32 components.
Implementations§
Source§impl Vector4
impl Vector4
Sourcepub fn new(data: [f32; 4]) -> Self
pub fn new(data: [f32; 4]) -> Self
Creates a new 4-vector from the provided array data.
§Example
let v = Vector4::new([1.0, 2.0, 3.0, 4.0]);
assert_eq!(v.get(0), 1.0);Sourcepub fn zero() -> Self
pub fn zero() -> Self
Creates a zero vector (all components are 0.0).
§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let zero = Vector4::zero();
assert_eq!(zero.get(2), 0.0);Sourcepub fn get(&self, index: usize) -> f32
pub fn get(&self, index: usize) -> f32
Gets the value at the specified index using a method call.
Prefer using the index operator vector[index] for more idiomatic access.
§Panics
Panics if index is out of bounds (>= 4).
§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let v = Vector4::new([1.0, 2.0, 3.0, 4.0]);
assert_eq!(v.get(1), 2.0);Sourcepub fn set(&mut self, index: usize, value: f32)
pub fn set(&mut self, index: usize, value: f32)
Sets the value at the specified index using a method call.
Prefer using the mutable index operator vector[index] = value
for more idiomatic modification.
§Panics
Panics if index is out of bounds (>= 4).
§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let mut v = Vector4::zero();
v.set(3, 5.0);
assert_eq!(v.get(3), 5.0);Sourcepub fn dot(&self, other: &Self) -> f32
pub fn dot(&self, other: &Self) -> f32
Calculates the dot (inner) product of this vector with another vector.
result = self[0]*other[0] + self[1]*other[1] + self[2]*other[2] + self[3]*other[3]
§Example
use crate::bb_geometry::linear_algebra::vector4::*;
let v1 = Vector4::new([1.0, 2.0, 3.0, 4.0]);
let v2 = Vector4::new([5.0, 6.0, 7.0, 8.0]);
// 1*5 + 2*6 + 3*7 + 4*8 = 5 + 12 + 21 + 32 = 70
assert_eq!(v1.dot(&v2), 70.0);pub fn l2_norm(&self) -> f32
pub fn l1_norm(&self) -> f32
pub fn is_almost_zero(&self) -> bool
Sourcepub fn wedge_product(&self, other: &Self) -> Matrix4x4
pub fn wedge_product(&self, other: &Self) -> Matrix4x4
Calculates the wedge product (antisymmetric outer product) of two vectors.
Returns a 4x4 antisymmetric linear_algebra M where M[i][j] = self[i]*other[j] - self[j]*other[i].
This represents the bivector formed by the two vectors.
§Example
use crate::bb_geometry::linear_algebra::vector4::*;
use crate::bb_geometry::linear_algebra::matrix4x4::*;
let u = Vector4::new([1.0, 2.0, 0.0, 0.0]);
let v = Vector4::new([0.0, 3.0, 4.0, 0.0]);
let wedge_matrix = u.wedge_product(&v);
// M[0][1] = u[0]*v[1] - u[1]*v[0] = 1*3 - 2*0 = 3.0
assert_eq!(wedge_matrix[(0, 1)], 3.0);
// M[1][0] = u[1]*v[0] - u[0]*v[1] = 2*0 - 1*3 = -3.0
assert_eq!(wedge_matrix[(1, 0)], -3.0);
// M[0][2] = u[0]*v[2] - u[2]*v[0] = 1*4 - 0*0 = 4.0
assert_eq!(wedge_matrix[(0, 2)], 4.0);
// M[1][2] = u[1]*v[2] - u[2]*v[1] = 2*4 - 0*3 = 8.0
assert_eq!(wedge_matrix[(1, 2)], 8.0);
// M[0][0] should be 0
assert_eq!(wedge_matrix[(0, 0)], 0.0);
// M[3][x] should be 0 as u[3] and v[3] are 0
assert_eq!(wedge_matrix[(3, 0)], 0.0);
assert_eq!(wedge_matrix[(0, 3)], 0.0);Trait Implementations§
Source§impl Add<&Vector4> for &Vector4
Implements vector addition using the + operator (&Vector4 + &Vector4).
impl Add<&Vector4> for &Vector4
Implements vector addition using the + operator (&Vector4 + &Vector4).
Source§impl Index<usize> for Vector4
Allows accessing vector components using index vector[index].
impl Index<usize> for Vector4
Allows accessing vector components using index vector[index].
§Panics
Panics if index is out of bounds (>= 4).
Source§impl IndexMut<usize> for Vector4
Allows mutating vector components using index vector[index] = value.
impl IndexMut<usize> for Vector4
Allows mutating vector components using index vector[index] = value.
§Panics
Panics if index is out of bounds (>= 4).
Source§impl Mul<&Vector4> for &Matrix4x4
Implements Matrix * Vector multiplication (&Matrix4x4 * &Vector4).
Treats the vector as a column vector.
impl Mul<&Vector4> for &Matrix4x4
Implements Matrix * Vector multiplication (&Matrix4x4 * &Vector4).
Treats the vector as a column vector.
Source§impl Sub<&Vector4> for &Vector4
Implements vector subtraction using the - operator (&Vector4 - &Vector4).
impl Sub<&Vector4> for &Vector4
Implements vector subtraction using the - operator (&Vector4 - &Vector4).