7 releases (4 breaking)
| 0.5.1 | Aug 28, 2025 |
|---|---|
| 0.5.0 | Jun 4, 2025 |
| 0.4.0 | Jun 4, 2025 |
| 0.3.1 | Jun 3, 2025 |
| 0.1.0 | Jun 2, 2025 |
#1186 in Math
134 downloads per month
16KB
374 lines
vector_2d_3d
- Simple small library for 2D and 3D vectors.
- Please feel free to review and leave comments on my GitHub page.
Vector2D
#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
pub struct Vector2D {
pub x: f32,
pub y: f32,
}
Functions
Constructors
new- creates a vector from the x and y coordinatefrom_coord- creates a vector from the x and y coordinatefrom_coords- creates a vector from the two x and y coordinatesfrom_mag_theta- creates a vector from the given magnitude and degrees (in radians) from the x-axisihat- creates the unit vector of the x-axisjhat- creates the unit vector of the y-axis
Methods
perpendicular_cw- returns a vector that is perpendicular clockwise to the current vectorperpendicular_ccw- returns a vector that is perpendicular counter clockwise to the current vectormagnitude- returns the magnitude of the current vectordirection_as_unit_vector- returns a unit vector with the same direction of the current vectordirection- returns the degrees (theta) between the vector and the x-axisdot_product- returns the dot product of the current vector andotherdot_product_with_angle- returns the dot product of the current vector andotherusing their magintudes and the angle between themcross_product- programmers implementation of the cross product between 2D vectors, since it doesn't exist
Traits
Vector2D implements the Add<f32>, Sub<f32>, Mul<f32>, Div<f32> traits.
Vector3D
#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
pub struct Vector3D {
pub x: f32,
pub y: f32,
pub z: f32,
}
Functions
Constructors
new- creates a vector from the x, y and z coordinatefrom_coord- creates a vector from the x, y and z coordinatefrom_mag_alpha_beta_gamma- creates a vector from the magnitude and angles between the x, y and z-axesfrom_mag_asimuthal_polar- creates a vector from the magnitude and angle azimuthal and polarihat- creates the unit vector of the x-axisjhat- creates the unit vector of the y-axiskhat- creates the unit vector of the z-axis
Methods
perpendicular- returns a vector that is perpendicular to the current vectormagnitude- returns the magnitude of the current vectordirection_as_unit_vector- returns a unit vector with the same direction as the current vectordirection_from_axes- returns the angles between the different axesdirection- returns the direction of the current vectordot_product- returns the dot product of the current vector andothercross_product- returns the cross product of the current vector andother
Traits
Vector3D implements the Add<f32>, Sub<f32>, Mul<f32>, Div<f32> traits.
Dependencies
~0.6–1.4MB
~31K SLoC