1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// fisica::math
//
//! # The math
//!
//! ## Vectors
//!
//! Vectors are represented as an array of scalar values.
//! They represent quantities in 2D or 3D space.
//!
//! The vector $\bm{a}$ is the agroupation of the $z$, $y$, and $z$ coordinate
//! values along the X, Y and Z axes.
//!
//! $$
//! \bm{a} = \begin{bmatrix} x \cr y \cr z \end{bmatrix}
//! $$
//!
//! A vector can represent a unique [Position] in space. And any position can be
//! interpreted as a *change of position*.
//!
//! The change in position (from $\bm{a}_0$ to $\bm{a}_1$ where
//! $\Delta x = x_1 - x_0$ and similarly for $\Delta y$ and $\Delta z$)
//! would be represented as:
//!
//! $$
//! \bm{a} = \begin{bmatrix} \Delta x \cr \Delta y \cr \Delta z \end{bmatrix}
//! $$
//!
//! A change of position can be split into two elements: $\bm{a} = d\bm{n}$.
//! Where $d$ is the directionless [Magnitude] of the change (a scalar),
//! and $\bm{n}$ is the *unit vector* that represents the [Direction],
//! with a magnitude of 1.
//!
//!
//! To find $d$ (where $|\bm{a}|$ is the magnitude of the vector)
//! we can use the Pythagorean theorem in 3D:
//!
//! $$
//! d = |\bm{a}| = \sqrt{x^2 + y^2 + z^2}
//! $$
//!
//! And to find $\bm{n}$ (where $\widehat{\bm{a}}$ is the unit vector in the
//! direction of $\bm{a}$) we can use the formula $\bm{a} = d\bm{n}$ in the form:
//!
//! $$
//! \bm{n} = \widehat{\bm{a}} = \frac{1}{d}\thinspace\bm{a}
//! $$
//!
//! Finding $\bm{n}$ is called *normalizing*, and decomposing a vector into its
//! two components its called the *normal form* of the vector.
//!
//! ```
//! # use fisica::{Direction, Position};
//! assert_eq![
//! Position::new(2., 3., 4.).normalize(),
//! Direction::new(0.3713906763541037, 0.5570860145311556, 0.7427813527082074)
//! ];
//! ```
//!
//! Note: *To compare two magnitudes it is much faster to omit the square root
//! and just compare their magnitude squares: $(x^2 + y^2 + z^2)$*.
//!
//! ### Scalar and vector multiplication
//!
//! As previously shown in the normalization equations, it's possible to
//! multiply a scalar $k$ by a vector $\bm{a}$, like this:
//!
//! $$
//! k\bm{a} = k\begin{bmatrix} x \cr y \cr z \end{bmatrix} =
//! \begin{bmatrix} kx \cr ky \cr kz \end{bmatrix}
//! $$
//!
//! To divide a vector by a scalar:
//!
//! $$
//! a / b = a \times \frac{1}{b}
//! $$
//!
// f64 → Dvec3, Dquat, DMat3
// f32 → Vec3, Quat, Mat3
pub use ;
/// The floating point type used for magnitudes
pub type Magnitude = f64;
// The vector type to use
pub type V3 = DVec3;
/// Orientation
pub type Orientation = DQuat;
/// Rotation Matrix
pub type Matrix = DMat3;