pub struct Direction { /* private fields */ }Expand description
Direction is a vector quantity that represents a change in Position.
Position and Direction are two sides of the same coin.
We can also think of any position as a change of position from the
origin (Position::ZERO) to the target location.
Implementations§
Source§impl Direction
§Methods
impl Direction
§Methods
pub fn to_array(&self) -> [Magnitude; 3]
pub fn x(&self) -> Magnitude
pub fn y(&self) -> Magnitude
pub fn z(&self) -> Magnitude
Sourcepub fn magnitude(&self) -> Magnitude
pub fn magnitude(&self) -> Magnitude
Returns the Magnitude of the current Direction.
$$ d = |\bm{a}| = \sqrt{x^2 + y^2 + z^2} $$
Sourcepub fn magnitude_squared(&self) -> Magnitude
pub fn magnitude_squared(&self) -> Magnitude
Returns the square of the Magnitude of the current Direction.
This is faster than getting the Magnitude since we avoid having to
calculate the square root of the sum of the vector components.
This can be useful if we just need to compare magnitudes.
$$ d^2 = |\bm{a}|^2 = x^2 + y^2 + z^2 $$
Sourcepub fn normalize(&self) -> Direction
pub fn normalize(&self) -> Direction
Returns the normalized vector, as a unit vector.
That is the Direction with a Magnitude of 1.
$$ \bm{n} = \widehat{\bm{a}} = \frac{1}{d}\thinspace\bm{a} = \frac{\bm{a}}{|\bm{a}|} $$
Sourcepub fn cross(&self, other: Self) -> Self
pub fn cross(&self, other: Self) -> Self
Returns the cross product.
Also known as the vector product. It allows to point in a Direction
orthogonal to both vectors.
$$ \bm{a}\times\bm{b} = \begin{bmatrix} a_x \cr a_y \cr a_z \end{bmatrix} \times \begin{bmatrix} b_x \cr b_y \cr b_z \end{bmatrix} = \begin{bmatrix} a_y b_z - a_z b_y \cr a_z b_x - a_x b_z \cr a_x b_y - a_y b_x \end{bmatrix} $$
Sourcepub fn dot(&self, other: Self) -> Magnitude
pub fn dot(&self, other: Self) -> Magnitude
Returns the dot product.
Also known as the scalar product. It allows us to calculate the
Magnitude of one vector in the direction of another.
$$ \bm{a}\cdot\bm{b} = \begin{bmatrix} a_x \cr a_y \cr a_z \end{bmatrix} \cdot \begin{bmatrix} b_x \cr b_y \cr b_z \end{bmatrix} = a_x b_x + a_y b_y + a_z b_z $$
Trait Implementations§
Source§impl AddAssign for Direction
impl AddAssign for Direction
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl DivAssign<f64> for Direction
impl DivAssign<f64> for Direction
Source§fn div_assign(&mut self, other: Magnitude)
fn div_assign(&mut self, other: Magnitude)
/= operation. Read moreSource§impl MulAssign<f64> for Direction
impl MulAssign<f64> for Direction
Source§fn mul_assign(&mut self, other: Magnitude)
fn mul_assign(&mut self, other: Magnitude)
*= operation. Read moreSource§impl SubAssign for Direction
impl SubAssign for Direction
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read more