pub struct Vector {
pub x: f64,
pub y: f64,
pub z: f64,
}Expand description
A free vector in space.
Fields§
§x: f64X component.
y: f64Y component.
z: f64Z component.
Implementations§
Source§impl Vector
impl Vector
Sourcepub const fn from_array([x, y, z]: [f64; 3]) -> Self
pub const fn from_array([x, y, z]: [f64; 3]) -> Self
A vector from an array.
Sourcepub fn cross(self, other: Self) -> Self
pub fn cross(self, other: Self) -> Self
Cross product. Right-handed: X.cross(Y) == Z.
Each component is a two-term difference ab - cd, evaluated without a
fused multiply-add on purpose. An FMA rounds one product and not the
other, which destroys the exact cancellation that makes the cross
product of collinear vectors come out at exactly zero.
Sourcepub fn triple(self, a: Self, b: Self) -> f64
pub fn triple(self, a: Self, b: Self) -> f64
Scalar triple product self · (a × b): the signed volume of the
parallelepiped the three vectors span.
Sourcepub fn square_magnitude(self) -> f64
pub fn square_magnitude(self) -> f64
Squared magnitude. Prefer this to Vector::magnitude when comparing
lengths: it avoids a square root and the rounding that comes with it.
Sourcepub fn normalized(self, tol: Tolerances) -> OgeomResult<Self>
pub fn normalized(self, tol: Tolerances) -> OgeomResult<Self>
This vector scaled to unit length.
§Errors
OgeomError::Construction if the
magnitude is below tol.confusion(), or if any component is non-finite.
Normalizing a near-zero vector amplifies whatever noise it holds into an
arbitrary direction, so it is refused rather than approximated.
Sourcepub fn is_zero(self, tol: Tolerances) -> bool
pub fn is_zero(self, tol: Tolerances) -> bool
Whether the magnitude is within tol.confusion() of zero.
Sourcepub fn is_equal(self, other: Self, tol: Tolerances) -> bool
pub fn is_equal(self, other: Self, tol: Tolerances) -> bool
Whether two vectors agree component-wise within tol.confusion().
Sourcepub fn angle(self, other: Self, tol: Tolerances) -> OgeomResult<f64>
pub fn angle(self, other: Self, tol: Tolerances) -> OgeomResult<f64>
Angle to other, in [0, π].
Uses atan2 of the cross and dot products rather than acos of the
normalized dot product: acos loses most of its precision for nearly
parallel or nearly antiparallel vectors, which is exactly where angle
tests matter.
§Errors
OgeomError::Construction if either
vector is degenerate.
Sourcepub fn signed_angle(
self,
other: Self,
reference: Self,
tol: Tolerances,
) -> OgeomResult<f64>
pub fn signed_angle( self, other: Self, reference: Self, tol: Tolerances, ) -> OgeomResult<f64>
Angle to other measured about reference, in (-π, π].
Positive when self turns towards other counter-clockwise as seen from
the tip of reference.
§Errors
OgeomError::Construction if any vector
is degenerate, or if reference is not perpendicular to both within
tol.angular().
Sourcepub fn is_parallel(self, other: Self, tol: Tolerances) -> bool
pub fn is_parallel(self, other: Self, tol: Tolerances) -> bool
Whether self and other point the same way, within tol.angular().
Sourcepub fn is_collinear(self, other: Self, tol: Tolerances) -> bool
pub fn is_collinear(self, other: Self, tol: Tolerances) -> bool
Whether self and other are parallel, ignoring sense.
Sourcepub fn is_normal(self, other: Self, tol: Tolerances) -> bool
pub fn is_normal(self, other: Self, tol: Tolerances) -> bool
Whether self and other are perpendicular, within tol.angular().
Sourcepub fn projected_onto(self, other: Self, tol: Tolerances) -> OgeomResult<Self>
pub fn projected_onto(self, other: Self, tol: Tolerances) -> OgeomResult<Self>
Trait Implementations§
Source§impl AddAssign for Vector
impl AddAssign for Vector
Source§fn add_assign(&mut self, o: Self)
fn add_assign(&mut self, o: Self)
+= operation. Read moreSource§impl AddAssign<Vector> for Point
impl AddAssign<Vector> for Point
Source§fn add_assign(&mut self, v: Vector)
fn add_assign(&mut self, v: Vector)
+= operation. Read moreimpl Copy for Vector
Source§impl DivAssign<f64> for Vector
impl DivAssign<f64> for Vector
Source§fn div_assign(&mut self, s: f64)
fn div_assign(&mut self, s: f64)
/= operation. Read moreSource§impl MulAssign<f64> for Vector
impl MulAssign<f64> for Vector
Source§fn mul_assign(&mut self, s: f64)
fn mul_assign(&mut self, s: f64)
*= operation. Read moreimpl StructuralPartialEq for Vector
Auto Trait Implementations§
impl Freeze for Vector
impl RefUnwindSafe for Vector
impl Send for Vector
impl Sync for Vector
impl Unpin for Vector
impl UnsafeUnpin for Vector
impl UnwindSafe for Vector
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, Right> ClosedAdd<Right> for T
impl<T, Right> ClosedAddAssign<Right> for Twhere
T: ClosedAdd<Right> + AddAssign<Right>,
impl<T, Right> ClosedDiv<Right> for T
impl<T, Right> ClosedDivAssign<Right> for Twhere
T: ClosedDiv<Right> + DivAssign<Right>,
impl<T, Right> ClosedMul<Right> for T
impl<T, Right> ClosedMulAssign<Right> for Twhere
T: ClosedMul<Right> + MulAssign<Right>,
impl<T> ClosedNeg for Twhere
T: Neg<Output = T>,
impl<T, Right> ClosedSub<Right> for T
impl<T, Right> ClosedSubAssign<Right> for Twhere
T: ClosedSub<Right> + SubAssign<Right>,
impl<T> Scalar for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.