Vector3D

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 add(&self, other: &Vector3D) -> Vector3D

向量加法操作。

§参数
  • other: 另一个向量。
§返回值

返回两个向量相加的结果,结果是一个新的 Vector3D 实例。

§示例
use rs_math::vector::vector_3d::Vector3D;

let vector1 = Vector3D { x: 1.0, y: 2.0, z: 3.0 };
let vector2 = Vector3D { x: 4.0, y: 5.0, z: 6.0 };
let result = vector1.add(&vector2);
Source

pub fn subtract(&self, other: &Vector3D) -> Vector3D

向量减法操作。

§参数
  • other: 被减的向量。
§返回值

返回两个向量相减的结果,结果是一个新的 Vector3D 实例。

§示例
use rs_math::vector::vector_3d::Vector3D;

let vector1 = Vector3D { x: 1.0, y: 2.0, z: 3.0 };
let vector2 = Vector3D { x: 4.0, y: 5.0, z: 6.0 };
let result = vector1.subtract(&vector2);
Source

pub fn scalar_multiply(&self, scalar: f64) -> Vector3D

数量乘法操作。

§参数
  • scalar: 乘以向量的标量。
§返回值

返回数量乘法的结果,结果是一个新的 Vector3D 实例。

§示例
use rs_math::vector::vector_3d::Vector3D;

let vector = Vector3D { x: 1.0, y: 2.0, z: 3.0 };
let scalar = 2.0;
let result = vector.scalar_multiply(scalar);
Source

pub fn cross_product(&self, other: &Vector3D) -> Vector3D

计算两个向量的叉积。

§参数
  • other: 另一个向量。
§返回值

返回两个向量的叉积,结果是一个新的 Vector3D 实例。

§示例
use rs_math::vector::vector_3d::Vector3D;

let vector1 = Vector3D { x: 1.0, y: 2.0, z: 3.0 };
let vector2 = Vector3D { x: 4.0, y: 5.0, z: 6.0 };
let cross_product = vector1.cross_product(&vector2);
Source

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

计算两个向量的点积。

§参数
  • other: 另一个向量。
§返回值

返回两个向量的点积。

§示例
use rs_math::vector::vector_3d::Vector3D;

let vector1 = Vector3D { x: 1.0, y: 2.0, z: 3.0 };
let vector2 = Vector3D { x: 4.0, y: 5.0, z: 6.0 };
let dot_product = vector1.dot_product(&vector2);
Source

pub fn magnitude(&self) -> f64

计算向量的模长。

§返回值

返回向量的模长。

§示例
use rs_math::vector::vector_3d::Vector3D;

let vector = Vector3D { x: 3.0, y: 4.0, z: 5.0 };
let magnitude = vector.magnitude();
Source

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

计算两个向量之间的夹角(弧度)。

§参数
  • other:要计算夹角的另一个向量。
§返回值

返回两个向量之间的夹角(弧度)。

§示例
use rs_math::vector::vector_3d::Vector3D;

let vector1 = Vector3D { x: 3.0, y: 2.0, z: 1.0 };
let vector2 = Vector3D { x: 1.0, y: 4.0, z: 2.0 };
let angle = vector1.angle_between(&vector2);

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.