Vec3

Struct Vec3 

Source
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: f32

Implementations§

Source§

impl Vec3

Source

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 ) );
Source

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


Source

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


Source

pub fn from_angle(theta: &f32, phi: &f32, in_mag: &Option<f32>) -> Vec3

Generates a new instance of Vec3 based on a entered angles with a magnitude of 1

§Examples
  

   
Source

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


Source

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 ) );
Source

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 ) );
Source

pub fn add(&mut self, rhs: &Vec3)

Adds the components from the rhs Vec3 to the corresponding components of self

§Examples
  

   
Source

pub fn angle_between(&self, rhs: &Vec3) -> f32

Calculates the angle between self and a passed in Vec3

§Examples
Source

pub fn constrain( &mut self, x_rng: &Range<f32>, y_rng: &Range<f32>, z_rng: &Range<f32>, )

§Examples


Source

pub fn cross(&mut self, rhs: &Vec3) -> Vec3

Generates a new instance of Vec3 which is perpendicular to the self instance

§Examples
  

   
Source

pub fn dist(&self, rhs: &Vec3) -> f32

Calculates the distance between self and the Vec3 passed in

§Examples


Source

pub fn dist_sq(&self, rhs: &Vec3) -> f32

Calculates the distance squared between self and the Vec3 passed in

§Examples
  

   
Source

pub fn dbg(&self)

Prints debug information of self to terminal

§Examples
  

   
Source

pub fn dot(&self, rhs: &Vec3) -> f32

Calculates the dot product between self and a passed in Vec3

§Examples
  

   
Source

pub fn div(&mut self, rhs: &f32)

Divides the components of self by a scalar value rhs

§Examples
  

   
Source

pub fn div2(&mut self, rhs: &Vec3)

Divides the components of self by a Vec3 rhs

§Examples


Source

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 );
Source

pub fn mag(&self) -> f32

Calculates the magnitude of self

§Examples
  

   
Source

pub fn mag_sq(&self) -> f32

Calculates the magnitude squared of self

§Examples
  

   
Source

pub fn mult(&mut self, rhs: &f32)

Multiplies the components of self by a scalar value rhs

§Examples
  

   
Source

pub fn mult2(&mut self, rhs: &Vec3)

Multiplies the components of self by a Vec3 rhs

§Examples


Source

pub fn norm(&mut self)

Normalizes the magnitude of self to 1, angle is unchanged

§Examples
  

   
Source

pub fn phi(&self) -> f32

Calculates the theta of self

§Examples
  

   
Source

pub fn rem(&mut self, rhs: &f32)

Sets the components of self to the remainder of scalar division by rhs

§Examples
  

   
Source

pub fn rotate(&mut self, theta: &f32, phi: &f32)

Rotates self by the angle entered

§Examples
  

   
Source

pub fn set( &mut self, input1: &f32, input2: &f32, input3: &f32, coord_system: &CoordSystem, )

Sets components of vector to values entered

§Examples
  

   
Source

pub fn set_mag(&mut self, input: &f32)

Sets the magnitude of self

§Examples
  

   
Source

pub fn set_theta(&mut self, input: &f32)

Sets the theta of self

§Examples
  

   
Source

pub fn set_phi(&mut self, input: &f32)

Sets the phi of self

§Examples
  

   
Source

pub fn sub(&mut self, rhs: &Vec3)

Subtracts the components of the rhs Vec3 from the corresponding components of self

§Examples
  

   
Source

pub fn system(&self) -> CoordSystem

Returns the current coordinate system

§Examples
  

   
Source

pub fn theta(&self) -> f32

Calculates the theta of self

§Examples
  

   

Trait Implementations§

Source§

impl Add for Vec3

Implements Add for Vec3

§Examples



Source§

type Output = Vec3

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Vec3

Implements AddAssign for Vec3

§Examples



Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Vec3

Source§

fn clone(&self) -> Vec3

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 Vec3

Source§

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

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

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§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Div for Vec3

Implements Div for Vec3

§Examples



Source§

type Output = Vec3

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

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)

Performs the /= operation. Read more
Source§

impl Mul for Vec3

Implements Mul for Vec3

§Examples



Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for Vec3

Implements MulAssign for Vec3

§Examples



Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl PartialEq for Vec3

Implements PartialEq for Vec3

§Examples

  

Source§

fn eq(&self, rhs: &Self) -> bool

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

fn ne(&self, rhs: &Self) -> bool

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

impl Rem for Vec3

Implements Rem for Vec3

§Examples



Source§

type Output = Vec3

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl RemAssign for Vec3

Implements RemAssign for Vec3

§Examples



Source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Source§

impl Sub for Vec3

Implements Sub for Vec3

§Examples



Source§

type Output = Vec3

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for Vec3

Implements SubAssign for Vec3

§Examples



Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Copy for Vec3

Auto Trait Implementations§

§

impl Freeze for Vec3

§

impl RefUnwindSafe for Vec3

§

impl Send for Vec3

§

impl Sync for Vec3

§

impl Unpin for Vec3

§

impl UnwindSafe for Vec3

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V