pub struct Ellipse { /* private fields */ }Expand description
表示椭圆的结构体。
§字段
h- 椭圆中心的 x 坐标。k- 椭圆中心的 y 坐标。a- 长轴的长度。b- 短轴的长度。phi- 旋转角度(可能为零)。
椭圆是一个二维图形,定义了平面上所有满足特定数学条件的点的集合。 椭圆可以通过其中心坐标、长轴和短轴的长度以及旋转角度来描述。 长轴是通过椭圆中心的两个焦点的距离,短轴是垂直于长轴的轴的长度。 旋转角度表示椭圆相对于坐标轴的旋转程度。
Implementations§
Source§impl Ellipse
impl Ellipse
Sourcepub fn eccentricity(&self) -> f64
pub fn eccentricity(&self) -> f64
Sourcepub fn print_equation(&self)
pub fn print_equation(&self)
输出椭圆的方程。
打印椭圆的标准方程,其中 (x - h)^2 / a^2 + (y - k)^2 / b^2 = 1。
§示例
use rs_math::graphical::ellipse::Ellipse;
let ellipse = Ellipse::new(5.0, 3.0, 0.0, 0.0, 45.0);
ellipse.print_equation();Sourcepub fn area(&self) -> f64
pub fn area(&self) -> f64
计算椭圆的面积。
使用椭圆的长轴和短轴计算椭圆的面积,公式为 πab,其中 a 为长轴长度,b 为短轴长度。
§示例
use rs_math::graphical::ellipse::Ellipse;
let ellipse = Ellipse::new(5.0, 3.0, 0.0, 0.0, 0.0);
let area = ellipse.area();
println!("椭圆面积:{}", area);Sourcepub fn estimate_circumference(&self) -> f64
pub fn estimate_circumference(&self) -> f64
估算椭圆的周长。
使用椭圆的长轴和短轴估算椭圆的周长。这是一个近似值,使用 Ramanujan 的公式: π * [3(a + b) - sqrt((3a + b)(a + 3b))]
§示例
use rs_math::graphical::ellipse::Ellipse;
let ellipse = Ellipse::new(5.0, 3.0, 0.0, 0.0, 0.0);
let circumference = ellipse.estimate_circumference();
println!("椭圆周长的估算值:{}", circumference);Sourcepub fn point_position(&self, x: f64, y: f64) -> PointPosition
pub fn point_position(&self, x: f64, y: f64) -> PointPosition
判断点和椭圆的关系并返回枚举值。
§参数
x- 点的 x 坐标。y- 点的 y 坐标。
§返回值
返回 PointPosition 枚举值,表示点和椭圆的关系。
§示例
use rs_math::graphical::ellipse::{Ellipse, PointPosition};
let ellipse = Ellipse::new(5.0, 3.0, 0.0, 0.0, 0.0);
let position = ellipse.point_position(2.0, 1.0);
match position {
PointPosition::OnEllipse => println!("点在椭圆上"),
PointPosition::InsideEllipse => println!("点在椭圆内部"),
PointPosition::OutsideEllipse => println!("点在椭圆外部"),
}Sourcepub fn fit(points: &[(f64, f64)]) -> Option<Ellipse>
pub fn fit(points: &[(f64, f64)]) -> Option<Ellipse>
通过拟合给定点集合来估算椭圆。
§参数
points- 包含待拟合椭圆的点集合。
§返回值
如果拟合成功,返回一个包含椭圆参数的 Option<Ellipse>;否则返回 None。
§注意
至少需要 5 个点进行椭圆拟合。
§示例
use rs_math::graphical::ellipse::Ellipse;
let points = vec![(1.0, 0.0), (0.0, 1.0), (-1.0, 0.0), (0.0, -1.0), (0.0, 0.0)];
let fitted_ellipse = Ellipse::fit(&points);
match fitted_ellipse {
Some(ellipse) => {
println!("拟合椭圆成功!");
ellipse.print_equation();
}
None => println!("拟合椭圆失败,至少需要 5 个点。"),
}Trait Implementations§
impl Copy for Ellipse
impl StructuralPartialEq for Ellipse
Auto Trait Implementations§
impl Freeze for Ellipse
impl RefUnwindSafe for Ellipse
impl Send for Ellipse
impl Sync for Ellipse
impl Unpin for Ellipse
impl UnwindSafe for Ellipse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more