Struct oxygen_quark::vector::vector3d::Vector3D
source · Fields§
§x: Fraction
§y: Fraction
§z: Fraction
Implementations§
source§impl Vector3D
impl Vector3D
sourcepub fn new(x: Fraction, y: Fraction, z: Fraction) -> Vector3D
pub fn new(x: Fraction, y: Fraction, z: Fraction) -> Vector3D
Generates a new Vector3D
extern crate oxygen_quark as quark;
use quark::vector::vector3d::*;
use quark::fraction::Fraction;
let x = Fraction::new(3, 1);
let y = Fraction::new(6, 1);
let z = Fraction::new(2, 1);
let vector = Vector3D::new(x, y, z);
// Prints out "(x: 3, y: 6, z: 2)"
println!("{}", vector);
sourcepub fn add(&self, other: &Vector3D) -> Vector3D
pub fn add(&self, other: &Vector3D) -> Vector3D
Adds two Vector3D
s and returns their sum.
let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D { x: x2, y: y2, z: z2 };
let result_vector = vector1.add(&vector2);
// Prints out "(x: 5, y: 11, z: (7/2))"
println!("{}", result_vector);
sourcepub fn subtract(&self, other: &Vector3D) -> Vector3D
pub fn subtract(&self, other: &Vector3D) -> Vector3D
Subtracts two Vector3D
s and returns their difference.
let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D { x: x2, y: y2, z: z2 };
let result_vector = vector1.subtract(&vector2);
// Prints out "(x: 1, y: 1, z: (1/2))"
println!("{}", result_vector);
sourcepub fn component_product(&self, other: &Vector3D) -> Vector3D
pub fn component_product(&self, other: &Vector3D) -> Vector3D
Returns a new Vector3D
containing the product of every component in a Vector3D
with the corresponding component in another one.
let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D::new(x2, y2, z2);
let result_vector = vector1.component_product(&vector2);
// Prints out "(x: 6, y: 30, 3)"
println!("{}", result_vector);
sourcepub fn dot_product(&self, other: &Vector3D) -> Fraction
pub fn dot_product(&self, other: &Vector3D) -> Fraction
Returns a Fraction
that is the result of the dot-product between two Vector3D
s.
use quark::fraction::Fraction;
let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D::new(x2, y2, z2);
let result = vector1.dot_product(&vector2);
// Prints out "39"
println!("{}", result);
sourcepub fn cross_product(&self, other: &Vector3D) -> Vector3D
pub fn cross_product(&self, other: &Vector3D) -> Vector3D
Returns a Vector3D
that is the cross-product between two other Vector3D
s.
let vector1 = Vector3D::new(x1, y1, z1);
let vector2 = Vector3D::new(x2, y2, z2);
let result_vector = vector1.cross_product(&vector2);
// Prints out "(x: -1, y: (-1/2), z: 3)"
println!("{}", result_vector);
sourcepub fn scale(&self, scale: Fraction) -> Vector3D
pub fn scale(&self, scale: Fraction) -> Vector3D
Returns a scaled Vector3D
.
let vector = Vector3D::new(x, y, z);
let scale = Fraction::new(5, 1);
// Prints out "(x: 25, y: 15, z: 30)"
println!("{}", vector.scale(scale));
Trait Implementations§
source§impl Ord for Vector3D
impl Ord for Vector3D
source§impl PartialOrd<Vector3D> for Vector3D
impl PartialOrd<Vector3D> for Vector3D
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more