pub struct LinearEquation {
pub a: f64,
pub b: f64,
pub c: f64,
}Expand description
代表二维平面上的直线方程。
Fields§
§a: f64直线方程的 x 系数。
b: f64直线方程的 y 系数。
c: f64直线方程的常数项。
Implementations§
Source§impl LinearEquation
impl LinearEquation
Sourcepub fn from_points(x1: f64, y1: f64, x2: f64, y2: f64) -> LinearEquation
pub fn from_points(x1: f64, y1: f64, x2: f64, y2: f64) -> LinearEquation
Sourcepub fn from_point_slope(x1: f64, y1: f64, slope: f64) -> Self
pub fn from_point_slope(x1: f64, y1: f64, slope: f64) -> Self
Sourcepub fn is_parallel_to(&self, other: &LinearEquation) -> bool
pub fn is_parallel_to(&self, other: &LinearEquation) -> bool
Sourcepub fn from_slope_intercept(m: f64, b: f64) -> Self
pub fn from_slope_intercept(m: f64, b: f64) -> Self
Sourcepub fn from_arc(
_radius: f64,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
) -> LinearEquation
pub fn from_arc( _radius: f64, x1: f64, y1: f64, x2: f64, y2: f64, ) -> LinearEquation
通过圆弧的两个端点计算切线方程的一般式表示。
§参数
radius- 圆弧的半径。x1- 第一个端点的 x 坐标。y1- 第一个端点的 y 坐标。x2- 第二个端点的 x 坐标。y2- 第二个端点的 y 坐标。
§返回值
返回包含切线方程的一般式表示的 LinearEquation 结构体实例。
§示例
use rs_math::graphical::linear_equation::LinearEquation;
let line = LinearEquation::from_arc(1.0, 0.0, 0.0, 1.0, 0.0);
assert_eq!(line.to_string(), "0x + y - 1 = 0");todo: 是否需要增加两点+半径求圆弧,再求切线方程
Sourcepub fn translate_along_x(&self, h: f64) -> LinearEquation
pub fn translate_along_x(&self, h: f64) -> LinearEquation
将直线沿 x 轴平移指定单位,返回新的直线方程。
§参数
h- 沿 x 轴的平移距离。
§返回值
返回包含平移后直线方程的一般式表示的 LinearEquation 结构体实例。
§示例
use rs_math::graphical::linear_equation::LinearEquation;
let line = LinearEquation { a: 1.0, b: 2.0, c: 3.0 };
let translated_line = line.translate_along_x(2.0);
assert_eq!(translated_line.to_string(), "1x + 2y - 1 = 0");Sourcepub fn rotate_around_origin(&self, theta: f64) -> LinearEquation
pub fn rotate_around_origin(&self, theta: f64) -> LinearEquation
Sourcepub fn rotate_around_point(
&self,
theta: f64,
center: (f64, f64),
) -> LinearEquation
pub fn rotate_around_point( &self, theta: f64, center: (f64, f64), ) -> LinearEquation
将直线绕任意点逆时针旋转指定弧度,返回新的直线方程。
§参数
theta- 逆时针旋转的弧度。center- 旋转中心的坐标。
§返回值
返回包含旋转后直线方程的一般式表示的 LinearEquation 结构体实例。
§示例
use rs_math::graphical::linear_equation::LinearEquation;
let line = LinearEquation { a: 1.0, b: 2.0, c: 3.0 };
let rotated_line = line.rotate_around_point(1.0, (0.0, 0.0));
// 根据旋转后的具体结果进行验证Sourcepub fn translate(&self, h: f64, k: f64) -> LinearEquation
pub fn translate(&self, h: f64, k: f64) -> LinearEquation
Sourcepub fn angles_with_axes(&self) -> (f64, f64)
pub fn angles_with_axes(&self) -> (f64, f64)
Sourcepub fn point_line_relationship(&self, point: &Point2D) -> PointLineRelationship
pub fn point_line_relationship(&self, point: &Point2D) -> PointLineRelationship
判断点与直线的位置关系。
§参数
point- 要判断的点的坐标。
§返回值
返回 PointLineRelationship 枚举,表示点与直线的位置关系。
§示例
use rs_math::graphical::linear_equation::{LinearEquation, PointLineRelationship};
use rs_math::graphical::point_2d::Point2D;
let line = LinearEquation { a: 1.0, b: -1.0, c: 0.0 };
let point = Point2D { x: 2.0, y: 2.0 };
let relationship = line.point_line_relationship(&point);
Sourcepub fn is_tangent_to_circle(&self, circle: &Circle) -> bool
pub fn is_tangent_to_circle(&self, circle: &Circle) -> bool
判断直线与圆是否相切。
§参数
circle- 圆的信息。
§返回值
如果直线与圆相切,返回 true;否则,返回 false。
§注意
在比较距离时,考虑到浮点数误差,使用了 EPSILON 常量。
§示例
use rs_math::graphical::linear_equation::LinearEquation;
use rs_math::graphical::circle::Circle;
let line = LinearEquation { a: 1.0, b: -1.0, c: 0.0 };
let circle = Circle::new(0.0, 0.0, 1.0);
let is_tangent = line.is_tangent_to_circle(&circle);
Sourcepub fn is_vertical_to_x_axis(&self) -> bool
pub fn is_vertical_to_x_axis(&self) -> bool
Sourcepub fn is_vertical_to_y_axis(&self) -> bool
pub fn is_vertical_to_y_axis(&self) -> bool
Sourcepub fn are_intersecting(&self, other: &LinearEquation) -> bool
pub fn are_intersecting(&self, other: &LinearEquation) -> bool
Sourcepub fn are_parallel(&self, other: &LinearEquation) -> bool
pub fn are_parallel(&self, other: &LinearEquation) -> bool
Sourcepub fn are_perpendicular(&self, other: &LinearEquation) -> bool
pub fn are_perpendicular(&self, other: &LinearEquation) -> bool
Sourcepub fn is_equal_to(&self, other: &LinearEquation) -> bool
pub fn is_equal_to(&self, other: &LinearEquation) -> bool
Sourcepub fn to_slope_intercept_form(&self) -> Option<(f64, f64)>
pub fn to_slope_intercept_form(&self) -> Option<(f64, f64)>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LinearEquation
impl RefUnwindSafe for LinearEquation
impl Send for LinearEquation
impl Sync for LinearEquation
impl Unpin for LinearEquation
impl UnwindSafe for LinearEquation
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