3个版本 (破坏性)
0.3.0 | 2019年2月2日 |
---|---|
0.2.0 | 2019年1月27日 |
0.1.0 | 2019年1月25日 |
#170 in #geometry
每月50次下载
在 8 个crate中使用 (直接使用4个)
33KB
657 行
vec3D
一个最小的Rust 3D向量库。设计时倾向于物理学的约定。灵感来自CLHEP Hep3Vector类。
约定
此模块使用物理学界描述球坐标的约定如下
- r - 径向距离
- theta - 极角
- phi - 方位角
以及柱坐标系
- r - 径向距离
- phi - 角度
- z - 沿z轴的高度
所有角度均以弧度为单位。
示例
use vec3D::Vec3D;
fn main() {
// Simple initialisation
let vec1 = Vec3D::new(1.0, 2.0, 3.0);
println!("{}", vec1); // Prints: "[1.0, 2.0, 3.0]"
// Operator overloads for clean code
let vec2 = Vec3D::new(3.0, 4.0, 5.0);
let vec3 = vec1 + vec2;
println!("{}", vec3); // Prints: "[4.0, 6.0, 8.0]"
let vec4 = vec3 * 2.0;
println!("{}", vec4); // Prints: "[8.0, 12.0, 16.0]"
// Common vector operations
let dot_product = vec3.dot(vec4);
println!("{}", dot_product); // Prints: "232"
let vec5 = Vec3D::new(1.0, 0.0, 0.0);
let vec6 = Vec3D::new(0.0, 1.0, 0.0);
let cross_product = vec5.cross(vec6);
println!("{}", cross_product); // Prints: "[0.0, 0.0, 1.0]"
// Plus initialisations from spherical/cylindrical coordinates, rotations and more
}
许可证
本项目采用MIT许可证(LICENSE 或 http://opensource.org/licenses/MIT)
依赖关系
~220KB