pub struct Vec3D {
pub x: f64,
pub y: f64,
pub z: f64,
}Fields§
§x: f64§y: f64§z: f64Implementations§
Source§impl Vec3D
impl Vec3D
Sourcepub fn new(x: f64, y: f64, z: f64) -> Vec3D
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}Sourcepub fn new_from_spherical_coordinates(
r: f64,
theta: f64,
phi: f64,
) -> Result<Vec3D, Vec3DError>
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 < 0theta < 0theta > PI
Sourcepub fn new_from_cylindrical_coordinates(
r: f64,
phi: f64,
z: f64,
) -> Result<Vec3D, Vec3DError>
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
Sourcepub fn inner_product(&self, other: Vec3D) -> f64
pub fn inner_product(&self, other: Vec3D) -> f64
Returns the inner product of this vector with another vector
Sourcepub fn dot(&self, other: Vec3D) -> f64
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}Sourcepub fn distance_to(&self, other: Vec3D) -> f64
pub fn distance_to(&self, other: Vec3D) -> f64
Returns the distance between this vector and another vector
Sourcepub fn distance_to2(&self, other: Vec3D) -> f64
pub fn distance_to2(&self, other: Vec3D) -> f64
Returns the distance^2 between this vector and another vector
Sourcepub fn cross(&self, other: Vec3D) -> Vec3D
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}Sourcepub fn pseudo_rapidity(&self) -> f64
pub fn pseudo_rapidity(&self) -> f64
Returns the pseudo-rapidity of the vector w.r.t the z-axis
Sourcepub fn rotated_x(&self, angle: f64) -> Vec3D
pub fn rotated_x(&self, angle: f64) -> Vec3D
Returns a new vector of the current vector rotated around the x-axis
Sourcepub fn rotated_y(&self, angle: f64) -> Vec3D
pub fn rotated_y(&self, angle: f64) -> Vec3D
Returns a new vector of the current vector rotated around the y-axis
Trait Implementations§
Source§impl AddAssign for Vec3D
impl AddAssign for Vec3D
Source§fn add_assign(&mut self, other: Vec3D)
fn add_assign(&mut self, other: Vec3D)
Performs the
+= operation. Read moreSource§impl DivAssign<f64> for Vec3D
impl DivAssign<f64> for Vec3D
Source§fn div_assign(&mut self, other: f64)
fn div_assign(&mut self, other: f64)
Performs the
/= operation. Read moreSource§impl MulAssign<f64> for Vec3D
impl MulAssign<f64> for Vec3D
Source§fn mul_assign(&mut self, other: f64)
fn mul_assign(&mut self, other: f64)
Performs the
*= operation. Read moreSource§impl SubAssign for Vec3D
impl SubAssign for Vec3D
Source§fn sub_assign(&mut self, other: Vec3D)
fn sub_assign(&mut self, other: Vec3D)
Performs the
-= operation. Read moreimpl Copy for Vec3D
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more