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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! # Robomath
//!
//! A lightweight, efficient, and generic mathematics library for 3D applications, with a focus on
//! robotics, games, and simulation. `robomath` provides essential tools for working with vectors,
//! quaternions, and 3x3 matrices, emphasizing simplicity and correctness for real-time applications.
//!
//! ## Key Features
//!
//! - **Generic Vectors**: `Vec2<T>` and `Vec3<T>` supporting various numeric types with operations
//! like addition, subtraction, multiplication, division, dot product, cross product, and clamping.
//! - **Quaternions**: Full-featured quaternion implementation for 3D rotations, including Euler angle
//! conversion, rotation matrices, Gibbs vectors, and numerically stable methods.
//! - **3x3 Matrices**: Matrix operations for linear algebra and transformations, including transpose,
//! determinant, trace, skew-symmetric matrices, and outer products.
//! - **Transformations**: Quaternion and matrix-based transformations for 3D rotations, with support
//! for inertial-to-body and body-to-inertial frame conversions.
//! - **Comprehensive Tests**: Well-tested with high test coverage for reliability.
//!
//! ## Getting Started
//!
//! Add `robomath` to your project by including it in your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! robomath = "0.1.0"
//! ```
//!
//! Here's a simple example that demonstrates rotating a vector using a quaternion:
//!
//! ```rust
//! use robomath::{Quaternion, vec3, Vec3};
//! use std::f32::consts::PI;
//!
//! // Define a vector to rotate
//! let point = vec3(1.0, 0.0, 0.0);
//!
//! // Create a quaternion for a 90-degree rotation around the Y-axis
//! let rotation = Quaternion::from_euler(0.0, PI/2.0, 0.0);
//!
//! // Convert the point to a pure quaternion
//! let pure_q = Quaternion::new(0.0, point.x, point.y, point.z);
//!
//! // Apply the rotation: q * p * q^-1
//! let rotated_pure_q = rotation * pure_q * rotation.inverse();
//!
//! // Extract the rotated vector
//! let rotated_point = vec3(rotated_pure_q.x, rotated_pure_q.y, rotated_pure_q.z);
//! println!("Rotated point: {:?}", rotated_point); // Should be approximately [0.0, 0.0, -1.0]
//! ```
//!
//! ## Usage
//!
//! The library provides ergonomic implementations of common 3D math operations. For detailed
//! examples, see the [Usage Examples](https://github.com/wboayue/robomath#usage-examples) section
//! in the README.
//!
//! ### Vectors
//!
//! Work with generic `Vec2<T>` and `Vec3<T>` types for 2D and 3D vector operations:
//! - Arithmetic: addition, subtraction, multiplication, division
//! - Methods: dot product, cross product, magnitude, clamping, etc.
//!
//! ### Quaternions
//!
//! Use `Quaternion` for efficient and numerically stable 3D rotations:
//! - Create from Euler angles or rotation matrices
//! - Extract Euler angles, Gibbs vectors, or rotation matrices
//! - Perform quaternion multiplication and conjugation
//!
//! ### Matrices
//!
//! Use `Mat3x3` for linear algebra operations:
//! - Basic operations: transpose, determinant, trace
//! - Advanced operations: skew-symmetric matrices, outer products
//!
//! ## Advanced Features
//!
//! - **Generic Types**: Vectors are generic over their component type `T`, with trait bounds for
//! arithmetic operations. See the README's [Generic Type Requirements](https://github.com/wboayue/robomath#generic-type-requirements) section.
//! - **Numerical Stability**: Methods like quaternion-to-rotation-matrix conversion are implemented
//! with numerical stability in mind.
//!
//! ## Limitations
//!
//! - Some quaternion methods (e.g., `inverse`) assume unit quaternions.
//! - Performance optimizations like SIMD are not currently implemented, prioritizing simplicity.
//! - Floating-point precision may affect operations with very large or small values.
//!
//! For more details, see the [Limitations](https://github.com/wboayue/robomath#limitations-and-assumptions)
//! section in the README.
//!
//! ## Contributing
//!
//! Contributions are welcome! Please see the [CONTRIBUTING](https://github.com/wboayue/robomath/blob/main/CONTRIBUTING.md)
//! guide for more information.
//!
//! ## License
//!
//! This library is licensed under the MIT License. See the [LICENSE](https://github.com/wboayue/robomath/blob/main/LICENSE)
//! file for details.
pub use *;
pub use *;
pub use *;
pub use *;
pub use PI;
/// Converts degrees to radians.
///
/// This function multiplies the input angle (in degrees) by π/180 to convert it to radians.
/// It uses `libm::PIf` for a precise value of π in a `no_std` environment.
///
/// # Arguments
///
/// * `degrees` - The angle in degrees.
///
/// # Returns
///
/// The angle in radians as an `f32`.
///
/// # Examples
///
/// ```
/// use robomath::to_radians;
///
/// let rad = to_radians(90.0);
/// assert!((rad - core::f32::consts::PI / 2.0).abs() < 1e-5);
/// ```