Struct Vector2D
Source pub struct Vector2D {
pub x: f64,
pub y: f64,
}
Expand description
定义二维向量结构体。
该结构体包含两个分量,分别表示向量的 x 和 y 坐标。
use rs_math::vector::vector_2d::Vector2D;
let v = Vector2D { x: 1.0, y: 2.0 };
创建新的二维向量。
该函数创建一个新的二维向量,其 x 坐标和 y 坐标分别为 x 和 y。
§返回值
返回新的二维向量。
use rs_math::vector::vector_2d::Vector2D;
let v = Vector2D::new(1.0, 2.0);
计算二维向量的模(长度)。
该函数使用欧几里得范数计算二维向量的模(长度)。
§返回值
返回二维向量的模(长度)。
use rs_math::vector::vector_2d::Vector2D;
let v = Vector2D::new(1.0, 2.0);
计算两个二维向量的和,返回一个新的向量。
该函数使用算术加法运算计算两个二维向量的和。
self:调用该方法的向量。
other:要与 self 相加的另一个向量。
§返回值
返回一个新的向量,表示 self 和 other 的和。
use rs_math::vector::vector_2d::Vector2D;
let v1 = Vector2D::new(1.0, 2.0);
let v2 = Vector2D::new(3.0, 4.0);
let v3 = v1.add(v2);
向量减法。
§返回值
返回新的向量,表示两个向量的差。
use rs_math::vector::vector_2d::Vector2D;
let vector1 = Vector2D { x: 3.0, y: 2.0 };
let vector2 = Vector2D { x: 1.0, y: 4.0 };
let result = vector1.subtract(vector2);
向量点积。
§返回值
返回两个向量的点积结果。
use rs_math::vector::vector_2d::Vector2D;
let vector1 = Vector2D { x: 3.0, y: 2.0 };
let vector2 = Vector2D { x: 1.0, y: 4.0 };
let result = vector1.dot_product(vector2);
向量叉积。
§返回值
返回两个向量的叉积结果。
use rs_math::vector::vector_2d::Vector2D;
let vector1 = Vector2D { x: 3.0, y: 2.0 };
let vector2 = Vector2D { x: 1.0, y: 4.0 };
let result = vector1.cross_product(vector2);
Immutably borrows from an owned value.
Read more
Mutably borrows from an owned value.
Read more
Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From<T> for U chooses to do.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.