Skip to main content

Direction

Struct Direction 

Source
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>

Source

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);
Source

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

pub fn normalize(x: f64, y: f64, z: f64) -> Self

Creates a direction from components (alias for new).

Provided for API symmetry with earlier versions.

Source

pub fn from_vec3(vec: Vector3<f64>) -> Self

Creates a direction from a nalgebra Vector3, normalizing.

Source§

impl<F: ReferenceFrame> Direction<F>

Source

pub fn new_unchecked(x: f64, y: f64, z: f64) -> Self

Creates a direction from raw components without normalization.

§Safety

The caller must ensure the components form a unit vector.

Source§

impl<F: ReferenceFrame> Direction<F>

Source

pub fn x(&self) -> f64

Returns the x-component.

Source

pub fn y(&self) -> f64

Returns the y-component.

Source

pub fn z(&self) -> f64

Returns the z-component.

Source

pub fn as_vec3(&self) -> Vector3<f64>

Returns the underlying nalgebra Vector3.

Source§

impl<F: ReferenceFrame> Direction<F>

Source

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);
Source

pub fn position<C, U>(&self, magnitude: Quantity<U>) -> Position<C, F, U>
where C: ReferenceCenter<Params = ()>, U: LengthUnit,

Creates a position at the given distance from the origin in this direction.

For centers with Params = (), this is a convenience method.

Source

pub fn position_with_params<C, U>( &self, center_params: C::Params, magnitude: Quantity<U>, ) -> Position<C, F, U>

Creates a position with explicit center parameters.

Source§

impl<F: ReferenceFrame> Direction<F>

Source

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

pub fn cross(&self, other: &Self) -> Option<Self>

Computes the cross product with another direction.

The result is normalized if non-zero (perpendicular directions).

Source

pub fn negate(&self) -> Self

Negates the direction (points in opposite direction).

Source

pub fn angle_to(&self, other: &Self) -> f64

Returns the angle between this direction and another, in radians.

Source§

impl<F: ReferenceFrame> Direction<F>

Source

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°)
Source§

impl<F: ReferenceFrame> Direction<F>

Source

pub fn display(&self) -> String

Returns a formatted string representation.

Trait Implementations§

Source§

impl<F: Clone + ReferenceFrame> Clone for Direction<F>

Source§

fn clone(&self) -> Direction<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + ReferenceFrame> Debug for Direction<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: ReferenceFrame> Display for Direction<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: ReferenceFrame> LowerExp for Direction<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: ReferenceFrame, U: LengthUnit> Mul<Direction<F>> for Quantity<U>

Source§

type Output = Vector<F, U>

The resulting type after applying the * operator.
Source§

fn mul(self, dir: Direction<F>) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: ReferenceFrame, U: LengthUnit> Mul<Quantity<U>> for Direction<F>

Source§

type Output = Vector<F, U>

The resulting type after applying the * operator.
Source§

fn mul(self, magnitude: Quantity<U>) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: ReferenceFrame> UpperExp for Direction<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.