Function convex_polygons_intersection_points

Source
pub fn convex_polygons_intersection_points(
    poly1: &[Point2<f32>],
    poly2: &[Point2<f32>],
    out: &mut Vec<Point2<f32>>,
)
Expand description

Computes the intersection points of two convex polygons.

This function takes two convex polygons and computes their intersection, returning the vertices of the resulting intersection polygon. The result is added to the out vector.

§Important Notes

§Arguments

  • poly1 - First convex polygon as a slice of vertices
  • poly2 - Second convex polygon as a slice of vertices
  • out - Output vector where intersection vertices will be appended

§Examples

// Define two overlapping squares
let square1 = vec![
    Point2::origin(),
    Point2::new(2.0, 0.0),
    Point2::new(2.0, 2.0),
    Point2::new(0.0, 2.0),
];

let square2 = vec![
    Point2::new(1.0, 1.0),
    Point2::new(3.0, 1.0),
    Point2::new(3.0, 3.0),
    Point2::new(1.0, 3.0),
];

let mut intersection = Vec::new();
convex_polygons_intersection_points(&square1, &square2, &mut intersection);

// The intersection should be a square from (1,1) to (2,2)
assert_eq!(intersection.len(), 4);

§See Also