pub fn ray_intersects_line_segment<F>(
ray: &(Vector2<F>, Vector2<F>),
line_segment: &(Vector2<F>, Vector2<F>),
) -> boolwhere
F: Copy + RealField + PartialOrd,Expand description
Implements the ray-casting algorithm to check if a ray intersects with a given line segment.
This method can be applied to polygons to calculate if a point is inside of a given polygon or outside of it.
use nalgebra::Vector2;
let line_segment = (
Vector2::from([1.0, 3.0]),
Vector2::from([1.0, 1.0]),
);
let ray = (
Vector2::from([4.0, 1.5]),
Vector2::from([2.0, 1.5]),
);
// This should look something like this:
// |
// | <------
// |
assert!(ray_intersects_line_segment(&ray, &line_segment));
// Chaning the order of arguments will look like this
// |
// | ------
// |
// v
assert!(!ray_intersects_line_segment(&line_segment, &ray));