Function bcar::intersect_circle_line [−][src]
pub fn intersect_circle_line(
c: Point,
r: f64,
p1: Point,
p2: Point
) -> Option<(Point, Point)>
Return intersection points of circle and line if exist.
See https://mathworld.wolfram.com/Circle-LineIntersection.html
Examples
match bcar::intersect_circle_line( bcar::Point::new(0.0, 0.0), 0.5, bcar::Point::new(-1.0, 0.0), bcar::Point::new(1.0, 0.0), ) { Some((p1, p2)) => { assert!((p1.x - -0.5).abs() < 1e-5); assert!((p1.y - 0.0).abs() < 1e-5); assert!((p2.x - 0.5).abs() < 1e-5); assert!((p2.y - 0.0).abs() < 1e-5); }, None => { assert!(false); } } match bcar::intersect_circle_line( bcar::Point::new(1.0, 1.0), 0.5, bcar::Point::new(-1.0, 0.0), bcar::Point::new(1.0, 0.0), ) { Some(_t) => { assert!(false); }, None => { assert!(true); } }