pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
/* private fields */
}Expand description
A three dimensional mathematical vector
§Examples
use miscmath::prelude::*;
let a = Vec3::default();
assert!( ( a.x < 0.00001 ) && ( a.y < 0.00001 ) && ( a.z < 0.00001 ) );Fields§
§x: f32§y: f32§z: f32Implementations§
Source§impl Vec3
impl Vec3
Sourcepub fn new(x: &f32, y: &f32, z: &f32) -> Vec3
pub fn new(x: &f32, y: &f32, z: &f32) -> Vec3
Generates a new instance of Vec3 initialized to chosen values and returns it
§Examples
use miscmath::prelude::*;
let a = Vec3::new( &5.6, &7.2, &6.8 );
assert!( ( ( a.x - 5.6 ) < 0.000001 ) && ( ( a.y - 7.2 ) < 0.000001 ) && ( ( a.z - 6.8 ) < 0.00001 ) );Sourcepub fn create_random(range_x: &Range<f32>) -> Vec3
pub fn create_random(range_x: &Range<f32>) -> Vec3
Generates a new instance of Vec3 initialized to random values in the range entered and returns it
§Examples
Sourcepub fn create_random3(
range_x: &Range<f32>,
range_y: &Range<f32>,
range_z: &Range<f32>,
) -> Vec3
pub fn create_random3( range_x: &Range<f32>, range_y: &Range<f32>, range_z: &Range<f32>, ) -> Vec3
Generates a new instance of Vec3 initialized to random values in the range entered and returns it
§Examples
Sourcepub fn from_rand_angle(range: &Range<f32>, mag: &Option<f32>) -> Vec3
pub fn from_rand_angle(range: &Range<f32>, mag: &Option<f32>) -> Vec3
Generates a new instance of Vec3 initialized to random values in the range entered and returns it
§Examples
Sourcepub fn random_unit(range: &Range<f32>) -> Vec3
pub fn random_unit(range: &Range<f32>) -> Vec3
Generates a new instance of Vec3 initialized to a magnitude of 1 and angles of random value in the range entered and returns it
§Examples
use std::f32::consts::TAU;
use miscmath::prelude::*;
let mut a = Vec3::random_unit( &( 0.0..TAU ) );
assert!( ( a.x - 1.0 < 0.00001 ) && ( a.y < TAU ) && ( a.z < TAU ) );Sourcepub fn unit() -> Vec3
pub fn unit() -> Vec3
Generates a new instance of Vec3 initialized as a unit vector with angles of 0 and returns it
§Examples
use miscmath::prelude::*;
let mut b = Vec3::unit();
assert!( ( b.x < 0.00001 ) && ( b.y < 0.00001 ) && ( b.z - 1.0 < 0.0001 ) );Sourcepub fn angle_between(&self, rhs: &Vec3) -> f32
pub fn angle_between(&self, rhs: &Vec3) -> f32
Sourcepub fn constrain(
&mut self,
x_rng: &Range<f32>,
y_rng: &Range<f32>,
z_rng: &Range<f32>,
)
pub fn constrain( &mut self, x_rng: &Range<f32>, y_rng: &Range<f32>, z_rng: &Range<f32>, )
§Examples
Sourcepub fn lerp(&mut self, rhs: &Vec3, amt: UnitF)
pub fn lerp(&mut self, rhs: &Vec3, amt: UnitF)
Linearly interpolates between self and a passed in Vec3
§Examples
use miscmath::prelude::*;
let mut a = Vec3::new( &5.6, &7.2, &6.8 );
let mut b = Vec3::default();
a.lerp( &b, UnitF::new( 0.5 ) );
assert!( ( ( a.x - 2.8 ) < 0.00001 ) && ( ( a.y - 3.6 ) < 0.00001 ) && ( a.z - 3.4 ) < 0.00001 );Sourcepub fn set(
&mut self,
input1: &f32,
input2: &f32,
input3: &f32,
coord_system: &CoordSystem,
)
pub fn set( &mut self, input1: &f32, input2: &f32, input3: &f32, coord_system: &CoordSystem, )
Sourcepub fn system(&self) -> CoordSystem
pub fn system(&self) -> CoordSystem
Trait Implementations§
Source§impl AddAssign for Vec3
Implements AddAssign for Vec3
impl AddAssign for Vec3
Implements AddAssign for Vec3
§Examples
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Default for Vec3
Implements Default for Vec3
Generates a new instance of Vec3 initialized to zero and returns it
impl Default for Vec3
Implements Default for Vec3 Generates a new instance of Vec3 initialized to zero and returns it
§Examples
use miscmath::prelude::*;
let a = Vec3::default();
assert!( ( a.x < 0.000001 ) && ( a.y < 0.000001 ) && ( a.z < 0.00001 ) );Source§impl DivAssign for Vec3
Implements DivAssign for Vec3
impl DivAssign for Vec3
Implements DivAssign for Vec3
§Examples
use miscmath::prelude::*;
let mut x = Vec3::new( &100.0, &50.0, &30.0 );
let y = Vec3::new( &2.0, &5.0 , &3.0 );
let z = Vec3::new( &50.0, &10.0, &10.0 );
x /= y;
assert_eq!( x, z );Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl MulAssign for Vec3
Implements MulAssign for Vec3
impl MulAssign for Vec3
Implements MulAssign for Vec3
§Examples
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl RemAssign for Vec3
Implements RemAssign for Vec3
impl RemAssign for Vec3
Implements RemAssign for Vec3
§Examples
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§impl SubAssign for Vec3
Implements SubAssign for Vec3
impl SubAssign for Vec3
Implements SubAssign for Vec3
§Examples
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more