2个版本
0.1.8 | 2024年7月6日 |
---|---|
0.1.7 | 2024年6月12日 |
0.1.6 |
|
0.1.4 |
|
#205 in 数学
77 每月下载量
14KB
101 行
aspect360:计算两个角度之间的角度
此crate基于ring360库,用于计算目标角度与或球或角度/或球的数组之间的角度。
此crate重新导出ring360,因此不需要单独安装它。
计算单个角度匹配
/// Cast two 64-bit floats to Ring360 values
let angle_1 = 74.7.to_360();
let angle_2 = 164.4.to_360();
// calculate the aspect to ±90º within a 2º orb
let result = angle_1.calc_aspect(&angle_2, 90.0, 2.0);
println!("{:.1}º and {:.1}º are {:.1}º apart, {:.1}º from the target aspect of {:.1}º with an orb of {:.1}. Matched: {}",
angle_1.degrees(),
angle_2.degrees(),
result.aspect(),
result.distance(),
result.target(),
result.orb(),
result.matched(),
);
/// Should read: 74.7º and 164.4º are 89.7º apart, -0.3 from the target aspect of 90.0º with an orb of 2.0. Match: true
从多个选项中找到第一个角度匹配
let lng_1 = 98.202928;
let lng_2 = 249.325729;
let angle_1 = lng_1.to_360();
let angle_2 = lng_2.to_360();
// List target aspect as pairs of target angles and orbs
let targets = [
(0.0, 8.0), // conjunction
(90.0, 5.0), // square
(120.0, 3.0), // trine
(180.0, 4.0) // opposition
].to_aspect_orbs(); // cast the tuple pairs to a vector of AspectOrb structs
let aspect_match_opt = angle_1.find_aspect(&angle_2, &targets);
if let Some(aspect_match) = aspect_match_opt {
println!(
"{:.6}º and {:.6}º have an an aspect match of {:.0}º within {:.6}º",
angle_1,
angle_2,
aspect_match.target(),
aspect_match.distance(),
);
// Should read: 98.202928º and 249.325729º have an an aspect match of 150º within 1.122801º
}
在角度定义可能重叠的情况下找到最佳匹配的角度
在实际应用中,如果角度定义不能重叠,find_aspect()方法将更有效,因为它将返回第一个匹配的AspectOrb对象。但是,当定义重叠时(例如,六分相仅比七分相远约8.57度),第一个匹配可能不是最佳匹配,如下例所示。
let lng_1 = 192.928202;
let lng_2 = 249.325729;
let angle_1 = lng_1.to_360();
let angle_2 = lng_2.to_360();
let targets = [
(30.0, 5.0), // semisextile
(45.0, 8.0), // semisquare
(360.0 / 7.0, 9.0), // septile 360/7 = approx. 51.428571
(60.0, 8.0), // sextile
(90.0, 8.0), // square
(120.0, 8.0), // trine
(150.0, 10.0) // quincunx
].to_aspect_orbs(); // cast to a vector of AspectOrb structs
let aspect_matches = angle_1.find_aspects(&angle_2, &targets);
println!("{} aspects have been matched within the specified ranges", aspect_matches.len());
// yields a vector with 2 matched AspectResults
// Two aspects are matched.
let first_match = angle_1.find_aspect(&angle_2, &targets);
// yields the first matched aspect even if it's not best aspect. In this case a septile with a wide orb of 9.0
println!("The first match is {}º from the target aspect of {}º", first_match.unwrap().divergence(), first_match.unwrap().target());
// prints: The first match is 4.968955571428566º from the target aspect of 51.42857142857143º
// However, the best match is sextile and not septile, which would have been matched first
let best_aspect_match = angle_1.find_best_aspect(&angle_2, &targets);
// Yields a sextile
println!("The best match is {}º from the target aspect of {}º", best_aspect_match.unwrap().divergence(), best_aspect_match.unwrap().target());
// prints: The best match is 3.6024730000000034º from the target aspect of 60º
结构体
AspectResult
实例方法
- aspect()-> f64 两个角度的角度,无论它们是否匹配。
- distance()-> f64 从目标角度的角度距离。可能产生负值
- divergence()-> f64 从目标角度的绝对角度距离。可能只产生零或正值
- target()-> f64 目标角度,始终是对称的,例如90度将匹配±90或±270
- matched()-> bool 如果角度与目标在指定的或球内进行角度匹配,则为真。
- orb() -> f64 角度匹配的容差
AspectOrb
一个简单的元组结构体,包含目标角度和或球,都是64位浮点数。任何包含表示目标角度和或球的f64值数组的或向量都可以通过to_aspect_orbs()
转换为AspectOrb对象。
实例方法
- target()-> f64 目标角度
- orb() -> f64 角度匹配的容差
特质
Aspect360
此特质仅在Ring360中实现,但任何64位浮点数都可以通过.to_360()扩展方法和以_f64结尾的变异方法转换为Ring360,这些方法接受正常的f64值作为比较角度,这些角度将在0度到360度的范围内进行归一化。
- calc_aspect(other: &Ring360, target: f64, orb: f64) -> AspectResult
- is_aspected(other: &Ring360, target: f64, orb: f64) -> bool
- calc_aspect_f64(other: f64, target: f64, orb: f64) -> AspectResult
- *find_aspect(other: &Ring360, targets: &[AspectOrb]) -> Option
- *find_aspects(other: &Ring360, targets: &[AspectOrb]) -> Vec
- *find_best_aspect(other: &Ring360, targets: &[AspectOrb]) -> Option
- is_aspected_f64(other: f64, target: f64, orb: f64) -> bool
开发笔记
版本 0.1.4 引入了两个新方法 find_aspects() 和 find_best_aspect(),用于处理方面定义(AspectOrb)可能重叠的情况。
版本 0.1.7 添加了一个新的特质 ToAspectOrb
,其中包含一个 to_aspect_orbs
方法,用于将一个简单的 (f64, f64) 元组数组转换为 AspectOrb() 结构体向量,以供 find_aspect()
、find_best_aspect()
和 find_aspects()
使用。这减少了样板代码。
依赖项
~19KB