Struct Vec3D

Source
pub struct Vec3D {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

Fields§

§x: f64§y: f64§z: f64

Implementations§

Source§

impl Vec3D

Source

pub fn new(x: f64, y: f64, z: f64) -> Vec3D

Examples found in repository?
examples/example.rs (line 5)
3fn main() {
4    // Simple initialisation
5    let vec1 = Vec3D::new(1.0, 2.0, 3.0);
6    println!("{}", vec1);               // Prints: "[1.0, 2.0, 3.0]"
7
8    // Operator overloads for clean code
9    let vec2 = Vec3D::new(3.0, 4.0, 5.0);
10    let vec3 = vec1 + vec2;
11    println!("{}", vec3);               // Prints: "[4.0, 6.0, 8.0]"
12
13    let vec4 = vec3 * 2.0;
14    println!("{}", vec4);               // Prints: "[8.0, 12.0, 16.0]"
15
16    // Common vector operations
17    let dot_product = vec3.dot(vec4);
18    println!("{}", dot_product);        // Prints: "232"
19
20    let vec5 = Vec3D::new(1.0, 0.0, 0.0);
21    let vec6 = Vec3D::new(0.0, 1.0, 0.0);
22    let cross_product = vec5.cross(vec6);
23    println!("{}", cross_product);      // Prints: "[0.0, 0.0, 1.0]"
24
25    // Plus initialisations from spherical/cylindrical coordinates, rotations and more
26}
Source

pub fn new_from_spherical_coordinates( r: f64, theta: f64, phi: f64, ) -> Result<Vec3D, Vec3DError>

Creates a new 3D vector from spherical coordinates

  • r - radial distance
  • theta - polar angle
  • phi - azimuthal angle
§Errors

Will return a Vec3DError if:

  • r < 0
  • theta < 0
  • theta > PI
Source

pub fn new_from_cylindrical_coordinates( r: f64, phi: f64, z: f64, ) -> Result<Vec3D, Vec3DError>

Creates a new 3D vector from cylindrical coordinates

  • r - radial distance
  • phi - angle
  • z - height along z-axis
§Errors

Will return a Vec3DError if:

  • r < 0
Source

pub fn zeros() -> Vec3D

Returns a new vector with a value of 0.0 in each axis

Source

pub fn ones() -> Vec3D

Returns a new vector with a value of 1.0 in each axis

Source

pub fn x_proj(&self) -> Vec3D

Returns the projection of the vector in the x-axis

Source

pub fn y_proj(&self) -> Vec3D

Returns the projection of the vector in the y-axis

Source

pub fn z_proj(&self) -> Vec3D

Returns the projection of the vector in the z-axis

Source

pub fn theta(&self) -> f64

Returns the vector’s theta value in spherical coordinates

Source

pub fn phi(&self) -> f64

Returns the vector’s phi value in spherical/cylindrical coordinates

Source

pub fn mag(&self) -> f64

Returns the vector’s magnitude

Source

pub fn mag2(&self) -> f64

Returns the vector’s magnitude^2

Source

pub fn norm(&self) -> Vec3D

Returns a new vector of the current vector normalised

Source

pub fn unit(&self) -> Vec3D

Alias for Vec3D::norm

Source

pub fn inner_product(&self, other: Vec3D) -> f64

Returns the inner product of this vector with another vector

Source

pub fn dot(&self, other: Vec3D) -> f64

Alias for Vec3D::inner_product

Examples found in repository?
examples/example.rs (line 17)
3fn main() {
4    // Simple initialisation
5    let vec1 = Vec3D::new(1.0, 2.0, 3.0);
6    println!("{}", vec1);               // Prints: "[1.0, 2.0, 3.0]"
7
8    // Operator overloads for clean code
9    let vec2 = Vec3D::new(3.0, 4.0, 5.0);
10    let vec3 = vec1 + vec2;
11    println!("{}", vec3);               // Prints: "[4.0, 6.0, 8.0]"
12
13    let vec4 = vec3 * 2.0;
14    println!("{}", vec4);               // Prints: "[8.0, 12.0, 16.0]"
15
16    // Common vector operations
17    let dot_product = vec3.dot(vec4);
18    println!("{}", dot_product);        // Prints: "232"
19
20    let vec5 = Vec3D::new(1.0, 0.0, 0.0);
21    let vec6 = Vec3D::new(0.0, 1.0, 0.0);
22    let cross_product = vec5.cross(vec6);
23    println!("{}", cross_product);      // Prints: "[0.0, 0.0, 1.0]"
24
25    // Plus initialisations from spherical/cylindrical coordinates, rotations and more
26}
Source

pub fn distance_to(&self, other: Vec3D) -> f64

Returns the distance between this vector and another vector

Source

pub fn distance_to2(&self, other: Vec3D) -> f64

Returns the distance^2 between this vector and another vector

Source

pub fn cross(&self, other: Vec3D) -> Vec3D

Returns the cross product of this vector with another vector

Examples found in repository?
examples/example.rs (line 22)
3fn main() {
4    // Simple initialisation
5    let vec1 = Vec3D::new(1.0, 2.0, 3.0);
6    println!("{}", vec1);               // Prints: "[1.0, 2.0, 3.0]"
7
8    // Operator overloads for clean code
9    let vec2 = Vec3D::new(3.0, 4.0, 5.0);
10    let vec3 = vec1 + vec2;
11    println!("{}", vec3);               // Prints: "[4.0, 6.0, 8.0]"
12
13    let vec4 = vec3 * 2.0;
14    println!("{}", vec4);               // Prints: "[8.0, 12.0, 16.0]"
15
16    // Common vector operations
17    let dot_product = vec3.dot(vec4);
18    println!("{}", dot_product);        // Prints: "232"
19
20    let vec5 = Vec3D::new(1.0, 0.0, 0.0);
21    let vec6 = Vec3D::new(0.0, 1.0, 0.0);
22    let cross_product = vec5.cross(vec6);
23    println!("{}", cross_product);      // Prints: "[0.0, 0.0, 1.0]"
24
25    // Plus initialisations from spherical/cylindrical coordinates, rotations and more
26}
Source

pub fn pseudo_rapidity(&self) -> f64

Returns the pseudo-rapidity of the vector w.r.t the z-axis

See: https://en.wikipedia.org/wiki/Pseudorapidity

Source

pub fn rotate_x(&mut self, angle: f64)

Rotates the vector around the x-axis

Source

pub fn rotated_x(&self, angle: f64) -> Vec3D

Returns a new vector of the current vector rotated around the x-axis

Source

pub fn rotate_y(&mut self, angle: f64)

Rotates the vector around the y-axis

Source

pub fn rotated_y(&self, angle: f64) -> Vec3D

Returns a new vector of the current vector rotated around the y-axis

Source

pub fn rotate_z(&mut self, angle: f64)

Rotates the vector around the z-axis

Source

pub fn rotated_z(&self, angle: f64) -> Vec3D

Returns a new vector of the current vector rotated around the z-axis

Source

pub fn approx_eq(self, other: Vec3D) -> bool

Returns true if points are approximately equal

Trait Implementations§

Source§

impl Add for Vec3D

Source§

type Output = Vec3D

The resulting type after applying the + operator.
Source§

fn add(self, other: Vec3D) -> Vec3D

Performs the + operation. Read more
Source§

impl AddAssign for Vec3D

Source§

fn add_assign(&mut self, other: Vec3D)

Performs the += operation. Read more
Source§

impl Clone for Vec3D

Source§

fn clone(&self) -> Vec3D

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Vec3D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Vec3D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<f64> for Vec3D

Source§

type Output = Vec3D

The resulting type after applying the / operator.
Source§

fn div(self, other: f64) -> Vec3D

Performs the / operation. Read more
Source§

impl DivAssign<f64> for Vec3D

Source§

fn div_assign(&mut self, other: f64)

Performs the /= operation. Read more
Source§

impl Mul<f64> for Vec3D

Source§

type Output = Vec3D

The resulting type after applying the * operator.
Source§

fn mul(self, other: f64) -> Vec3D

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Vec3D

Source§

fn mul_assign(&mut self, other: f64)

Performs the *= operation. Read more
Source§

impl Neg for Vec3D

Source§

type Output = Vec3D

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vec3D

Performs the unary - operation. Read more
Source§

impl PartialEq for Vec3D

Source§

fn eq(&self, other: &Vec3D) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for Vec3D

Source§

type Output = Vec3D

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vec3D) -> Vec3D

Performs the - operation. Read more
Source§

impl SubAssign for Vec3D

Source§

fn sub_assign(&mut self, other: Vec3D)

Performs the -= operation. Read more
Source§

impl Copy for Vec3D

Source§

impl Eq for Vec3D

Auto Trait Implementations§

§

impl Freeze for Vec3D

§

impl RefUnwindSafe for Vec3D

§

impl Send for Vec3D

§

impl Sync for Vec3D

§

impl Unpin for Vec3D

§

impl UnwindSafe for Vec3D

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.