Skip to main content

Vector3D

Struct Vector3D 

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

Three-dimensional vector.

Fields§

§x: f64

x-component

§y: f64

y-component

§z: f64

z-component

Implementations§

Source§

impl Vector3D

Source

pub const ZERO: Vector3D

Zero vector.

§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::ZERO, Vector3D::new(0.0, 0.0, 0.0));
Source

pub const X: Vector3D

Unit vector along x-axis.

§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::X, Vector3D::new(1.0, 0.0, 0.0));
Source

pub const Y: Vector3D

Unit vector along y-axis.

§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::Y, Vector3D::new(0.0, 1.0, 0.0));
Source

pub const Z: Vector3D

Unit vector along z-axis.

§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::Z, Vector3D::new(0.0, 0.0, 1.0));
Source

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

Create a new 3D vector.

§Examples
use geomcore::Vector3D;
let v = Vector3D::new(1.0, 2.0, 3.0);
assert_eq!(v.x, 1.0);
assert_eq!(v.y, 2.0);
assert_eq!(v.z, 3.0);
Source

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

Dot product.

§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::X.dot(Vector3D::Y), 0.0);
assert_eq!(Vector3D::X.dot(Vector3D::X), 1.0);
Source

pub fn cross(self, other: Vector3D) -> Vector3D

Cross product.

§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::X.cross(Vector3D::Y), Vector3D::Z);
assert_eq!(Vector3D::Y.cross(Vector3D::Z), Vector3D::X);
assert_eq!(Vector3D::Z.cross(Vector3D::X), Vector3D::Y);
Source

pub fn magnitude(self) -> f64

Magnitude (Euclidean length).

§Examples
use geomcore::Vector3D;
assert!((Vector3D::new(1.0, 2.0, 2.0).magnitude() - 3.0).abs() < 1e-10);
Source

pub fn square_magnitude(self) -> f64

Squared magnitude.

§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::new(1.0, 2.0, 2.0).square_magnitude(), 9.0);
Source

pub fn normalized(self) -> Option<Vector3D>

Normalized vector.

Returns None if the squared magnitude is below f64::MIN_POSITIVE.

§Examples
use geomcore::Vector3D;
let v = Vector3D::new(3.0, 4.0, 0.0);
let normalized = v.normalized().unwrap();
assert!((normalized.x - 0.6).abs() < 1e-10);
assert!((normalized.y - 0.8).abs() < 1e-10);
assert_eq!(normalized.z, 0.0);
Source

pub fn angle_with_ref(self, other: Vector3D, reference: Vector3D) -> f64

Signed angle from self to other around reference (right-hand rule), in (-π, π].

Uses atan2(reference.normalized · (self × other), self · other).

§Preconditions

The reference vector must be non-zero. If reference is a zero vector (squared magnitude ≤ f64::MIN_POSITIVE), the function cannot determine the sign and returns the unsigned angle in [0, π]: atan2(0.0, self · other). This collapses to 0 for self · other > 0 and π for self · other < 0.

§Examples
use std::f64::consts::PI;
use geomcore::Vector3D;
let angle = Vector3D::X.angle_with_ref(Vector3D::Y, Vector3D::Z);
assert!((angle - PI / 2.0).abs() < 1e-10);

Trait Implementations§

Source§

impl Add for Vector3D

Source§

type Output = Vector3D

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Vector3D> for Point3D

Source§

type Output = Point3D

The resulting type after applying the + operator.
Source§

fn add(self, vector: Vector3D) -> Point3D

Performs the + operation. Read more
Source§

impl Clone for Vector3D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Vector3D

Source§

impl Debug for Vector3D

Source§

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

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

impl Default for Vector3D

Source§

fn default() -> Self

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

impl Mul<Vector3D> for f64

Source§

type Output = Vector3D

The resulting type after applying the * operator.
Source§

fn mul(self, vector: Vector3D) -> Vector3D

Performs the * operation. Read more
Source§

impl Mul<f64> for Vector3D

Source§

type Output = Vector3D

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f64) -> Vector3D

Performs the * operation. Read more
Source§

impl Neg for Vector3D

Source§

type Output = Vector3D

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vector3D

Performs the unary - operation. Read more
Source§

impl PartialEq for Vector3D

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Vector3D

Source§

impl Sub for Vector3D

Source§

type Output = Vector3D

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Vector3D> for Point3D

Source§

type Output = Point3D

The resulting type after applying the - operator.
Source§

fn sub(self, vector: Vector3D) -> Point3D

Performs the - operation. 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.