pub struct Vector<const N: usize, T = Scalar> { /* private fields */ }Implementations§
Source§impl<T: Number, const N: usize> Vector<N, T>
impl<T: Number, const N: usize> Vector<N, T>
pub fn add(&self, other: &Self) -> Self
pub fn sub(&self, other: &Self) -> Self
pub fn neg(&self) -> Self
pub fn prod_scalar(&self, s: T) -> Self
pub fn prod_dot(&self, other: &Self) -> T
pub fn norm_sq(&self) -> T
pub fn norm(&self) -> T
Sourcepub fn try_norm(&self) -> GeopResult<T>
pub fn try_norm(&self) -> GeopResult<T>
|self|, failing where [Scalar::sqrt] refuses the squared length
instead of panicking like Self::norm.
pub fn normalize(&self) -> GeopResult<Self>
Sourcepub fn orthonormal_complement(&self) -> GeopResult<Vec<Self>>
pub fn orthonormal_complement(&self) -> GeopResult<Vec<Self>>
N - 1 orthonormal vectors perpendicular to self, or an error for
a zero self. They are the columns other than the first of the
Householder reflection H = I - 2 w wᵀ / (wᵀ w), w = v̂ + σ e_0,
which swaps v̂ = self / |self| and σ e_0: H is orthogonal, so its
columns are orthonormal, and all but the first are perpendicular to
v̂. The sign σ of v̂_0 keeps wᵀ w = 2 (1 + |v̂_0|) >= 2 away
from cancellation, so the result is well conditioned for every v̂.
Sourcepub fn distance_to_segment(&self, a: &Self, b: &Self) -> T
pub fn distance_to_segment(&self, a: &Self, b: &Self) -> T
How far self is from the segment a..b.
Sourcepub fn could_be_equal(&self, other: &Self) -> bool
pub fn could_be_equal(&self, other: &Self) -> bool
True if every component could_be_equal other’s.
Source§impl<T: Number> Vector<3, T>
impl<T: Number> Vector<3, T>
Sourcepub fn across(&self) -> GeopResult<[Self; 2]>
pub fn across(&self) -> GeopResult<[Self; 2]>
Two unit directions square to the unit vector self and to each
other: the first from whichever of x, y, z runs least along it
— the first no other definitely runs less along, so that an axis a
hair off one of them does not pick between two by noise. A free
choice, made the same way wherever a direction across an axis is
measured from: a joint’s turns, a frame’s x, a sketch’s parallel.
pub fn prod_cross(&self, other: &Self) -> Self
Sourcepub fn could_be_parallel(&self, other: &Self) -> bool
pub fn could_be_parallel(&self, other: &Self) -> bool
Whether self and other could be parallel, in either sense: their
cross product could be zero.
Sourcepub fn rotated_about(&self, axis: &Self, cos: T, sin: T) -> Self
pub fn rotated_about(&self, axis: &Self, cos: T, sin: T) -> Self
self turned about the unit vector axis by the angle with cosine
cos and sine sin (Rodrigues’ formula).
Sourcepub fn homogeneous(&self, w: T) -> Vector4<T>
pub fn homogeneous(&self, w: T) -> Vector4<T>
The point self with weight w, homogeneous: (w x, w y, w z, w).
Taken as it is where the weight is exactly one: multiplying by it
would only widen it by rounding.
Sourcepub fn dehomogenized(&self) -> GeopResult<Vector2<T>>
pub fn dehomogenized(&self) -> GeopResult<Vector2<T>>
The point the homogeneous 2-D point (w x, w y, w) stands for,
(x, y): each coordinate divided by the weight (not multiplied by
its inverse, which rounds twice).
Source§impl<T: Number> Vector<4, T>
impl<T: Number> Vector<4, T>
Sourcepub fn dehomogenized(&self) -> GeopResult<Vector3<T>>
pub fn dehomogenized(&self) -> GeopResult<Vector3<T>>
The point the homogeneous 3-D point (w x, w y, w z, w) stands for,
(x, y, z): each coordinate divided by the weight (not multiplied by
its inverse, which rounds twice).
Source§impl<T: Number> Vector<2, T>
impl<T: Number> Vector<2, T>
Sourcepub fn prod_cross(&self, other: &Self) -> T
pub fn prod_cross(&self, other: &Self) -> T
The 2-D cross product self.x * other.y - self.y * other.x: the z
component of the 3-D one, positive when other lies counter-clockwise
of self.
Sourcepub fn homogeneous(&self, w: T) -> Vector3<T>
pub fn homogeneous(&self, w: T) -> Vector3<T>
The point self with weight w, homogeneous: (w x, w y, w) —
taken as it is where the weight is exactly one (see
Vector3::homogeneous).
Source§impl<T: Number, const N: usize> Vector<N, T>
impl<T: Number, const N: usize> Vector<N, T>
pub fn from_array(data: [T; N]) -> Self
Sourcepub fn to_f64_array(&self) -> [f64; N]
pub fn to_f64_array(&self) -> [f64; N]
Its components as plain numbers (Scalar::to_f64, the midpoint):
for output and drawing, never for construction.
Source§impl<const N: usize> Vector<N>
impl<const N: usize> Vector<N>
Sourcepub fn everything() -> Self
pub fn everything() -> Self
Every component set to Scalar::ENTIRE — could_be_equals any
other vector of the same dimension componentwise.
Sourcepub fn interpolate(a: &Self, b: &Self, alpha: Scalar) -> Self
pub fn interpolate(a: &Self, b: &Self, alpha: Scalar) -> Self
Componentwise Scalar::interpolate: a at alpha=0, b at
alpha=1. See that method’s doc comment for why this beats a manual
a*(1-alpha) + b*alpha when components of a/b may coincide.
Trait Implementations§
impl<const N: usize, T: Copy> Copy for Vector<N, T>
Source§impl<'de, T: Number, const N: usize> Deserialize<'de> for Vector<N, T>
impl<'de, T: Number, const N: usize> Deserialize<'de> for Vector<N, T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<T: Number, const N: usize> Serialize for Vector<N, T>
A vector serializes as the array of its components’ midpoints — how it
travels to a viewer, which draws points, not enclosures — and reads back
from an array of plain numbers, each a sharp scalar.
impl<T: Number, const N: usize> Serialize for Vector<N, T>
A vector serializes as the array of its components’ midpoints — how it travels to a viewer, which draws points, not enclosures — and reads back from an array of plain numbers, each a sharp scalar.