pub fn triangle_plane_intersection(
v0: &Vertex,
v1: &Vertex,
v2: &Vertex,
z: f64,
) -> Option<(Point2D, Point2D)>Expand description
Find the line segment where a triangle intersects a horizontal Z plane
This function computes the intersection of a triangle with a plane at a given Z height. If the triangle crosses the plane, it returns a 2D line segment (in XY coordinates).
§Arguments
v0- First vertex of the trianglev1- Second vertex of the trianglev2- Third vertex of the trianglez- The Z height of the slicing plane
§Returns
An optional tuple of two 2D points representing the intersection line segment, or None if the triangle doesn’t intersect the plane
§Example
use lib3mf::{Vertex, mesh_ops::triangle_plane_intersection};
let v0 = Vertex::new(0.0, 0.0, 0.0);
let v1 = Vertex::new(10.0, 0.0, 5.0);
let v2 = Vertex::new(5.0, 10.0, 0.0);
if let Some((p1, p2)) = triangle_plane_intersection(&v0, &v1, &v2, 2.5) {
println!("Intersection segment: {:?} to {:?}", p1, p2);
}