pub struct Vector3D {
pub x: f64,
pub y: f64,
pub z: f64,
}Expand description
Three-dimensional vector.
Fields§
§x: f64x-component
y: f64y-component
z: f64z-component
Implementations§
Source§impl Vector3D
impl Vector3D
Sourcepub const ZERO: Vector3D
pub const ZERO: Vector3D
Zero vector.
§Examples
use geomcore::Vector3D;
assert_eq!(Vector3D::ZERO, Vector3D::new(0.0, 0.0, 0.0));Sourcepub const X: Vector3D
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));Sourcepub const Y: Vector3D
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));Sourcepub const Z: Vector3D
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));Sourcepub const fn new(x: f64, y: f64, z: f64) -> Vector3D
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);Sourcepub fn dot(self, other: Vector3D) -> f64
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);Sourcepub fn cross(self, other: Vector3D) -> Vector3D
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);Sourcepub fn magnitude(self) -> f64
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);Sourcepub fn square_magnitude(self) -> f64
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);Sourcepub fn normalized(self) -> Option<Vector3D>
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);Sourcepub fn angle_with_ref(self, other: Vector3D, reference: Vector3D) -> f64
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);