Struct Vector3D

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

Fields§

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

Implementations§

Source§

impl Vector3D

Source

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

This creates a new 3d vector with the four given entries.

Source

pub fn length_l1(&self) -> f64

This gives back the l1 length of a 3d vector, i.e. the maximum of absolute values of its components.

§Example:
use bb_geometry::vector3d::Vector3D;
let length = Vector3D::new(-5.0, -2.2, 0.0).length_l1();
assert_eq!(length, 5.0);
Source

pub fn is_close_to_zero(self: &Vector3D) -> bool

This checks whether a 3d vector is close to the zero vector, up to crate::ALMOST_ZERO

§Example:
use bb_geometry::ALMOST_ZERO;
use bb_geometry::vector3d::Vector3D;
let a = Vector3D::new(ALMOST_ZERO, ALMOST_ZERO, ALMOST_ZERO);
let b = Vector3D::new(0.99 * ALMOST_ZERO, 0.99 * ALMOST_ZERO, 0.99 * ALMOST_ZERO);
assert_eq!(a.is_close_to_zero(), false);
assert_eq!(b.is_close_to_zero(), true);
Source

pub fn plus(self: &Vector3D, a: &Vector3D) -> Vector3D

This adds two 3d vectors

§Example:
use bb_geometry::vector3d::Vector3D;
let a = Vector3D::new(1.0, 2.0,  4.0);
let b = Vector3D::new(-1.0, 4.0,  -3.1);
let c = Vector3D::new(0.0, 6.0,  0.9);
assert!(a.plus(&b).almost_equals(&c));
Source

pub fn minus(self: &Vector3D, a: &Vector3D) -> Vector3D

This subtracts two 3d vectors

§Example:
use bb_geometry::vector3d::Vector3D;
let a = Vector3D::new(1.0, 2.0,  4.0);
let b = Vector3D::new(-1.0, 4.0, -3.1);
let c = Vector3D::new(2.0, -2.0,  7.1);
assert!(a.minus(&b).almost_equals(&c));
Source

pub fn almost_equals(self: &Vector3D, a: &Vector3D) -> bool

This compares two 3d vectors up to crate::ALMOST_ZERO.

§Example:
use bb_geometry::vector3d::Vector3D;
let a = Vector3D::new(1.0, 2.0, 3.0);
let b = Vector3D::new(1.00001, 2.0, 3.0);
let c = Vector3D::new(1.0000000001, 2.0, 3.0);
assert_eq!(a.almost_equals(&b), false);
assert_eq!(a.almost_equals(&c), true);
Source

pub fn revert(&self) -> Vector3D

This replaces a 3d vector with its negative

§Examples
use bb_geometry::vector3d::Vector3D;
let a = Vector3D::new(1.0, 2.0, 3.0);
let b = Vector3D::new(-1.0, -2.0, -3.0);
assert!(a.revert().almost_equals(&b));
Source

pub fn generate_random_vectors(n: usize) -> Vec<Vector3D>

This generates a 3d vector of length n containing randomly generated 4d vectors.

§Example:
use bb_geometry::vector3d::Vector3D;
let n = 10;
let list = Vector3D::generate_random_vectors(n);
assert_eq!(list.len(), n);
Source

pub fn random_vector() -> Vector3D

This generates a random 3d vector with entire between -1.0 and 1.0.

§Example:
use bb_geometry::vector3d::Vector3D;
let a = Vector3D::random_vector();
assert!(a.length_l1() <= 1.0);
Source

pub fn from_reference(vector_reference: &Vector3D) -> Vector3D

Source

pub fn components(&self) -> [f64; 3]

Trait Implementations§

Source§

impl Debug for Vector3D

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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, 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