#vector-2d #3d #3d-vector #vector-3d #2d-and-3d #github-page

vector_2d_3d

Simple small library for 2D and 3D vectors

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

Download history 73/week @ 2025-05-27 362/week @ 2025-06-03 3/week @ 2025-06-10 1/week @ 2025-07-22 6/week @ 2025-08-19 113/week @ 2025-08-26 15/week @ 2025-09-02

134 downloads per month

MIT license

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 coordinate
  • from_coord - creates a vector from the x and y coordinate
  • from_coords - creates a vector from the two x and y coordinates
  • from_mag_theta - creates a vector from the given magnitude and degrees (in radians) from the x-axis
  • ihat - creates the unit vector of the x-axis
  • jhat - creates the unit vector of the y-axis

Methods

  • perpendicular_cw - returns a vector that is perpendicular clockwise to the current vector
  • perpendicular_ccw - returns a vector that is perpendicular counter clockwise to the current vector
  • magnitude - returns the magnitude of the current vector
  • direction_as_unit_vector - returns a unit vector with the same direction of the current vector
  • direction - returns the degrees (theta) between the vector and the x-axis
  • dot_product - returns the dot product of the current vector and other
  • dot_product_with_angle - returns the dot product of the current vector and other using their magintudes and the angle between them
  • cross_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 coordinate
  • from_coord - creates a vector from the x, y and z coordinate
  • from_mag_alpha_beta_gamma - creates a vector from the magnitude and angles between the x, y and z-axes
  • from_mag_asimuthal_polar - creates a vector from the magnitude and angle azimuthal and polar
  • ihat - creates the unit vector of the x-axis
  • jhat - creates the unit vector of the y-axis
  • khat - creates the unit vector of the z-axis

Methods

  • perpendicular - returns a vector that is perpendicular to the current vector
  • magnitude - returns the magnitude of the current vector
  • direction_as_unit_vector - returns a unit vector with the same direction as the current vector
  • direction_from_axes - returns the angles between the different axes
  • direction - returns the direction of the current vector
  • dot_product - returns the dot product of the current vector and other
  • cross_product - returns the cross product of the current vector and other

Traits

Vector3D implements the Add<f32>, Sub<f32>, Mul<f32>, Div<f32> traits.

Dependencies

~0.6–1.4MB
~31K SLoC