pub struct Circle {
pub x: f64,
pub y: f64,
pub radius: f64,
}Expand description
表示一个圆的结构体。
Fields§
§x: f64圆的中心坐标
y: f64§radius: f64圆的半径
Implementations§
Source§impl Circle
impl Circle
Sourcepub fn from_points_and_radius(
point1: &Point2D,
point2: &Point2D,
radius: f64,
) -> Option<Circle>
pub fn from_points_and_radius( point1: &Point2D, point2: &Point2D, radius: f64, ) -> Option<Circle>
通过两点和半径创建圆。
§参数
point1- 圆上的第一个点。point2- 圆上的第二个点。radius- 圆的半径。
§返回值
如果给定半径有效,返回一个包含圆心和半径的 Circle 结构体实例;否则返回 None。
§示例
use rs_math::graphical::point_2d::Point2D;
use rs_math::graphical::circle::Circle;
let point1 = Point2D { x: 0.0, y: 0.0 };
let point2 = Point2D { x: 1.0, y: 0.0 };
let radius = 0.5;
let circle = Circle::from_points_and_radius(&point1, &point2, radius);Sourcepub fn from_points(p1: &Point2D, p2: &Point2D, p3: &Point2D) -> Option<Circle>
pub fn from_points(p1: &Point2D, p2: &Point2D, p3: &Point2D) -> Option<Circle>
通过三个点创建圆。
§参数
p1- 圆上的第一个点。p2- 圆上的第二个点。p3- 圆上的第三个点。
§返回值
如果给定三个点共线,返回 None;否则返回一个包含圆心和半径的 Circle 结构体实例。
§示例
use rs_math::graphical::point_2d::Point2D;
use rs_math::graphical::circle::Circle;
let p1 = Point2D { x: 0.0, y: 0.0 };
let p2 = Point2D { x: 1.0, y: 0.0 };
let p3 = Point2D { x: 0.0, y: 1.0 };
let circle = Circle::from_points(&p1, &p2, &p3);Sourcepub fn is_point_inside(&self, point_x: f64, point_y: f64) -> bool
pub fn is_point_inside(&self, point_x: f64, point_y: f64) -> bool
Sourcepub fn generate_points(&self, num_points: usize) -> Vec<Point2D>
pub fn generate_points(&self, num_points: usize) -> Vec<Point2D>
Sourcepub fn is_point_on_arc(
&self,
start_angle: f64,
end_angle: f64,
point: &Point2D,
) -> bool
pub fn is_point_on_arc( &self, start_angle: f64, end_angle: f64, point: &Point2D, ) -> bool
判断点是否在圆弧上。
§参数
start_angle- 圆弧的起始角度。end_angle- 圆弧的结束角度。point- 待判断的点。
§返回值
如果给定点在圆弧上,返回 true;否则返回 false。
§示例
use rs_math::graphical::circle::Circle;
use rs_math::graphical::point_2d::Point2D;
let circle = Circle::new(0.0, 0.0, 1.0);
let start_angle = 0.0;
let end_angle = std::f64::consts::PI;
let point = Point2D { x: 1.0, y: 0.0 };
let is_on_arc = circle.is_point_on_arc(start_angle, end_angle, &point);Sourcepub fn is_angle_in_range(
&self,
start_angle: f64,
end_angle: f64,
point: &Point2D,
) -> bool
pub fn is_angle_in_range( &self, start_angle: f64, end_angle: f64, point: &Point2D, ) -> bool
判断夹角是否在指定范围内的辅助函数。
§参数
start_angle- 范围的起始角度。end_angle- 范围的结束角度。point- 待判断的点。
§返回值
如果给定点的夹角在指定范围内,返回 true;否则返回 false。
§示例
use rs_math::graphical::circle::Circle;
use rs_math::graphical::point_2d::Point2D;
let circle = Circle::new(0.0, 0.0, 1.0);
let start_angle = 0.0;
let end_angle = std::f64::consts::PI;
let point = Point2D { x: 1.0, y: 0.0 };
let is_in_range = circle.is_angle_in_range(start_angle, end_angle, &point);Sourcepub fn is_point_on_circle_boundary(&self, point: &Point2D) -> bool
pub fn is_point_on_circle_boundary(&self, point: &Point2D) -> bool
Sourcepub fn find_line_intersection(&self, p1: &Point2D, p2: &Point2D) -> Vec<Point2D>
pub fn find_line_intersection(&self, p1: &Point2D, p2: &Point2D) -> Vec<Point2D>
寻找与直线的交点。
§参数
p1- 直线上的第一个点。p2- 直线上的第二个点。
§返回值
返回一个包含交点的 Vec<Point2D>。
§示例
use rs_math::graphical::circle::Circle;
use rs_math::graphical::point_2d::Point2D;
let circle = Circle::new(0.0, 0.0, 1.0);
let point1 = Point2D { x: -2.0, y: 0.0 };
let point2 = Point2D { x: 2.0, y: 0.0 };
let intersections = circle.find_line_intersection(&point1, &point2);Sourcepub fn circles_intersect(&self, other: &Circle) -> bool
pub fn circles_intersect(&self, other: &Circle) -> bool
Sourcepub fn circles_touch(&self, other: &Circle) -> bool
pub fn circles_touch(&self, other: &Circle) -> bool
Sourcepub fn circle_contains(&self, other: &Circle) -> bool
pub fn circle_contains(&self, other: &Circle) -> bool
Sourcepub fn circle_inside_rectangle(&self, rect: &Rectangle) -> bool
pub fn circle_inside_rectangle(&self, rect: &Rectangle) -> bool
判断圆心是否在矩形内。
公式:circle_x >= rect.x1 && circle_x <= rect.x2 && circle_y >= rect.y1 && circle_y <= rect.y2
圆心的 x 坐标在矩形的 x 范围内,且圆心的 y 坐标在矩形的 y 范围内。
§参数
rect- 包含矩形的实例。
§返回值
如果圆心在矩形内,返回 true;否则返回 false。
§示例
use rs_math::graphical::circle::Circle;
use rs_math::graphical::rectangle::Rectangle;
let circle = Circle::new(1.0, 1.0, 2.0);
let rectangle = Rectangle::new(0.0, 0.0, 3.0, 3.0);
let is_inside = circle.circle_inside_rectangle(&rectangle);Sourcepub fn circle_on_rectangle_edge(&self, rect: &Rectangle) -> bool
pub fn circle_on_rectangle_edge(&self, rect: &Rectangle) -> bool
判断圆心是否在矩形的某个边上。
公式:
(circle_x == rect.x1 || circle_x == rect.x2) && circle_y >= rect.y1 && circle_y <= rect.y2或circle_x >= rect.x1 && circle_x <= rect.x2 && (circle_y == rect.y1 || circle_y == rect.y2)
圆心在矩形的 x 或 y 范围的一个边界上,但不在矩形内部。
§参数
rect- 包含矩形的实例。
§返回值
如果圆心在矩形的边上,返回 true;否则返回 false。
§示例
use rs_math::graphical::circle::Circle;
use rs_math::graphical::rectangle::Rectangle;
let circle = Circle::new(2.0, 2.0, 1.0);
let rectangle = Rectangle::new(1.0, 1.0, 3.0, 3.0);
let on_edge = circle.circle_on_rectangle_edge(&rectangle);Sourcepub fn circle_on_rectangle_corner(&self, rect: &Rectangle) -> bool
pub fn circle_on_rectangle_corner(&self, rect: &Rectangle) -> bool
判断圆心是否在矩形的角上。
公式:
(circle_x == rect.x1 && circle_y == rect.y1)或(circle_x == rect.x1 && circle_y == rect.y2)或(circle_x == rect.x2 && circle_y == rect.y1)或(circle_x == rect.x2 && circle_y == rect.y2)
圆心在矩形的 x 或 y 范围的一个边界上,并且与另一个边界相交。
§参数
rect- 包含矩形的实例。
§返回值
如果圆心在矩形的角上,返回 true;否则返回 false。
§示例
use rs_math::graphical::circle::Circle;
use rs_math::graphical::rectangle::Rectangle;
let circle = Circle::new(1.0, 1.0, 0.5);
let rectangle = Rectangle::new(0.0, 0.0, 2.0, 2.0);
let on_corner = circle.circle_on_rectangle_corner(&rectangle);Sourcepub fn bounding_box(&self) -> Rectangle
pub fn bounding_box(&self) -> Rectangle
获取圆的外接矩形。
外接矩形的左上角坐标为 (circle_x - radius, circle_y - radius),
右下角坐标为 (circle_x + radius, circle_y + radius)。
§返回值
返回一个包含外接矩形坐标的 Rectangle 结构体实例。
§示例
use rs_math::graphical::circle::Circle;
use rs_math::graphical::rectangle::Rectangle;
let circle = Circle::new(3.0, 4.0, 2.0);
let bounding_box = circle.bounding_box();Trait Implementations§
impl StructuralPartialEq for Circle
Auto Trait Implementations§
impl Freeze for Circle
impl RefUnwindSafe for Circle
impl Send for Circle
impl Sync for Circle
impl Unpin for Circle
impl UnwindSafe for Circle
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