pub struct Direction(/* private fields */);Expand description
A unit vector in space.
Implementations§
Source§impl Direction
impl Direction
Sourcepub fn new(v: Vector, tol: Tolerances) -> OgeomResult<Self>
pub fn new(v: Vector, tol: Tolerances) -> OgeomResult<Self>
Normalize v into a direction.
§Errors
OgeomError::Construction if v is
non-finite or shorter than tol.confusion().
Sourcepub fn from_coords(x: f64, y: f64, z: f64, tol: Tolerances) -> OgeomResult<Self>
pub fn from_coords(x: f64, y: f64, z: f64, tol: Tolerances) -> OgeomResult<Self>
Sourcepub fn unit(v: Vector, tol: Tolerances) -> OgeomResult<Self>
pub fn unit(v: Vector, tol: Tolerances) -> OgeomResult<Self>
A direction from a vector that is already a unit vector.
Checks rather than normalizes, and the distinction is the whole reason it exists: dividing a unit vector by its own magnitude does not give it back, it gives something a bit or two away. That is invisible until something has to reproduce a direction exactly: reading a document back from a file, above all, where the drift turns a round trip that should be the identity into one that changes the model a little every time.
§Errors
OgeomError::Construction if v is
non-finite, or its length differs from one by more than
tol.confusion().
Sourcepub fn dot(self, other: Self) -> f64
pub fn dot(self, other: Self) -> f64
Dot product with another direction: the cosine of the angle between
them, in [-1, 1] up to rounding.
Sourcepub fn dot_vector(self, v: Vector) -> f64
pub fn dot_vector(self, v: Vector) -> f64
Dot product with a free vector.
Sourcepub fn cross_vector(self, other: Self) -> Vector
pub fn cross_vector(self, other: Self) -> Vector
Cross product, as a free vector. Its magnitude is the sine of the angle between the two directions, so it is not itself a direction; for nearly parallel inputs it is nearly null.
Sourcepub fn cross_with(self, v: Vector) -> Vector
pub fn cross_with(self, v: Vector) -> Vector
Cross product with a free vector.
Its magnitude is the component of v perpendicular to this direction,
which makes it the accurate way to get a perpendicular distance:
subtracting the parallel component instead cancels catastrophically for
a point far along the direction.
Sourcepub fn cross(self, other: Self, tol: Tolerances) -> OgeomResult<Self>
pub fn cross(self, other: Self, tol: Tolerances) -> OgeomResult<Self>
Cross product, renormalized into a direction.
Collinearity is judged against the angular tolerance, not the linear one: for unit inputs the cross product’s magnitude is the sine of the angle between them, a dimensionless quantity that a length tolerance does not describe.
§Errors
OgeomError::Construction if the two
directions are collinear.
Sourcepub fn from_cross(a: Vector, b: Vector, tol: Tolerances) -> OgeomResult<Self>
pub fn from_cross(a: Vector, b: Vector, tol: Tolerances) -> OgeomResult<Self>
The unit normal to two free vectors.
The right way to build a normal from two edges of a triangle. Naively
normalizing a.cross(b) compares its magnitude (which is twice the
triangle’s area, and so scales as the square of the size) against a
length tolerance. A triangle a micron across then looks degenerate even
though its normal is perfectly well determined. The test here is
relative: |a x b| > tol.angular() * |a| * |b|, which asks the question
that actually matters, whether the two vectors are collinear, and gives
the same answer at every scale.
§Errors
OgeomError::Construction if a and b
are collinear, or either is null.
Sourcepub fn is_equal(self, other: Self, tol: Tolerances) -> bool
pub fn is_equal(self, other: Self, tol: Tolerances) -> bool
Whether the two point the same way, within tol.angular().
Sourcepub fn is_opposite(self, other: Self, tol: Tolerances) -> bool
pub fn is_opposite(self, other: Self, tol: Tolerances) -> bool
Whether the two point opposite ways, within tol.angular().
Sourcepub fn is_parallel(self, other: Self, tol: Tolerances) -> bool
pub fn is_parallel(self, other: Self, tol: Tolerances) -> bool
Whether the two 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 the two are perpendicular, within tol.angular().
Sourcepub fn any_perpendicular(self) -> Self
pub fn any_perpendicular(self) -> Self
Some direction perpendicular to this one.
Which one is unspecified but deterministic. Chosen by crossing with whichever axis this direction is least aligned with, so the cross product is never near-degenerate and the result is numerically sound for every input.
Sourcepub fn to_2d(self, tol: Tolerances) -> OgeomResult<Direction2>
pub fn to_2d(self, tol: Tolerances) -> OgeomResult<Direction2>
This direction with the Z component dropped, renormalized.
§Errors
OgeomError::Construction if this
direction is parallel to Z, leaving nothing to project.
Trait Implementations§
impl Copy for Direction
impl StructuralPartialEq for Direction
Auto Trait Implementations§
impl Freeze for Direction
impl RefUnwindSafe for Direction
impl Send for Direction
impl Sync for Direction
impl Unpin for Direction
impl UnsafeUnpin for Direction
impl UnwindSafe for Direction
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> ClosedNeg for Twhere
T: Neg<Output = T>,
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.