pub struct Direction<F: ReferenceFrame> { /* private fields */ }Expand description
A unit vector representing orientation in 3D space.
Directions are frame-dependent but center-independent (free vectors).
The internal storage is a Vector3<f64> with magnitude 1 (dimensionless).
§Type Parameters
F: The reference frame (e.g.,ICRS,EclipticMeanJ2000,Equatorial)
§Invariants
All public constructors ensure the direction is normalized. For unchecked
construction, use from_xyz_unchecked.
§Zero-Cost Abstraction
This type is #[repr(transparent)] over XYZ<f64>, ensuring no runtime
overhead compared to raw Vector3<f64>.
Implementations§
Source§impl<F: ReferenceFrame> Direction<F>
impl<F: ReferenceFrame> Direction<F>
Sourcepub fn new(x: f64, y: f64, z: f64) -> Self
pub fn new(x: f64, y: f64, z: f64) -> Self
Creates a direction from components, normalizing to unit length.
§Panics
Panics if the input vector is zero (cannot normalize).
§Example
use affn::cartesian::Direction;
use affn::frames::ReferenceFrame;
#[derive(Debug, Copy, Clone)]
struct WorldFrame;
impl ReferenceFrame for WorldFrame {
fn frame_name() -> &'static str { "WorldFrame" }
}
let dir = Direction::<WorldFrame>::new(3.0, 4.0, 0.0);
assert!((dir.x() - 0.6).abs() < 1e-12);
assert!((dir.y() - 0.8).abs() < 1e-12);Sourcepub fn try_new(x: f64, y: f64, z: f64) -> Option<Self>
pub fn try_new(x: f64, y: f64, z: f64) -> Option<Self>
Attempts to create a direction, returning None if the input is zero.
Source§impl<F: ReferenceFrame> Direction<F>
impl<F: ReferenceFrame> Direction<F>
Source§impl<F: ReferenceFrame> Direction<F>
impl<F: ReferenceFrame> Direction<F>
Source§impl<F: ReferenceFrame> Direction<F>
impl<F: ReferenceFrame> Direction<F>
Sourcepub fn scale<U: LengthUnit>(&self, magnitude: Quantity<U>) -> Displacement<F, U>
pub fn scale<U: LengthUnit>(&self, magnitude: Quantity<U>) -> Displacement<F, U>
Scales the direction by a length to produce a displacement vector.
§Example
use affn::cartesian::Direction;
use affn::frames::ReferenceFrame;
use qtty::*;
#[derive(Debug, Copy, Clone)]
struct WorldFrame;
impl ReferenceFrame for WorldFrame {
fn frame_name() -> &'static str { "WorldFrame" }
}
let dir = Direction::<WorldFrame>::new(1.0, 0.0, 0.0);
let vec = dir.scale(5.0 * M);
assert!((vec.x().value() - 5.0).abs() < 1e-12);Sourcepub fn position<C, U>(&self, magnitude: Quantity<U>) -> Position<C, F, U>
pub fn position<C, U>(&self, magnitude: Quantity<U>) -> Position<C, F, U>
Creates a position at the given distance from the origin in this direction.
For centers with Params = (), this is a convenience method.
Sourcepub fn position_with_params<C, U>(
&self,
center_params: C::Params,
magnitude: Quantity<U>,
) -> Position<C, F, U>where
C: ReferenceCenter,
U: LengthUnit,
pub fn position_with_params<C, U>(
&self,
center_params: C::Params,
magnitude: Quantity<U>,
) -> Position<C, F, U>where
C: ReferenceCenter,
U: LengthUnit,
Creates a position with explicit center parameters.
Source§impl<F: ReferenceFrame> Direction<F>
impl<F: ReferenceFrame> Direction<F>
Sourcepub fn dot(&self, other: &Self) -> f64
pub fn dot(&self, other: &Self) -> f64
Computes the dot product with another direction.
Returns cosine of the angle between directions (range: -1 to 1).
Source§impl<F: ReferenceFrame> Direction<F>
impl<F: ReferenceFrame> Direction<F>
Sourcepub fn to_spherical(&self) -> Direction<F>
pub fn to_spherical(&self) -> Direction<F>
Converts this Cartesian direction to spherical coordinates.
Returns a spherical direction with polar (latitude) and azimuth (longitude) angles in degrees. Angles are canonicalized to:
- polar in
[-90°, +90°] - azimuth in
[0°, 360°)
Trait Implementations§
Source§impl<F: ReferenceFrame> Display for Direction<F>
impl<F: ReferenceFrame> Display for Direction<F>
Source§impl<F: ReferenceFrame> LowerExp for Direction<F>
impl<F: ReferenceFrame> LowerExp for Direction<F>
Source§impl<F: ReferenceFrame, U: LengthUnit> Mul<Direction<F>> for Quantity<U>
impl<F: ReferenceFrame, U: LengthUnit> Mul<Direction<F>> for Quantity<U>
Source§impl<F: ReferenceFrame, U: LengthUnit> Mul<Quantity<U>> for Direction<F>
impl<F: ReferenceFrame, U: LengthUnit> Mul<Quantity<U>> for Direction<F>
Source§impl<F: ReferenceFrame> UpperExp for Direction<F>
impl<F: ReferenceFrame> UpperExp for Direction<F>
impl<F: Copy + ReferenceFrame> Copy for Direction<F>
Auto Trait Implementations§
impl<F> Freeze for Direction<F>
impl<F> RefUnwindSafe for Direction<F>where
F: RefUnwindSafe,
impl<F> Send for Direction<F>where
F: Send,
impl<F> Sync for Direction<F>where
F: Sync,
impl<F> Unpin for Direction<F>where
F: Unpin,
impl<F> UnsafeUnpin for Direction<F>
impl<F> UnwindSafe for Direction<F>where
F: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.