pub fn cuboid_segment_find_local_separating_edge_twoway(
cube1: &Cuboid,
segment2: &Segment,
pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)Expand description
Finds the best separating axis by testing edge-edge combinations between a cuboid and a segment (3D only).
In 3D, when a box collides with a line segment, the contact might occur along an axis perpendicular to both a cuboid edge and the segment itself. This function tests all such axes (cross products) to find the one with maximum separation.
§Parameters
cube1: The cuboidsegment2: The line segmentpos12: The position of the segment relative to the cuboid
§Returns
A tuple containing:
Real: The maximum separation found across all edge-edge axes- Positive: Shapes are separated
- Negative: Shapes are overlapping
Vector<Real>: The axis direction that gives this separation
§The 3 Axes Tested
A segment is a single edge, so we test cross products between:
- The segment’s direction (B - A)
- Each of the 3 cuboid edge directions (X, Y, Z)
This gives 3 potential separating axes. The function delegates to
cuboid_support_map_find_local_separating_edge_twoway
to perform the actual separation tests.
§Example
use parry3d::shape::{Cuboid, Segment};
use parry3d::query::sat::cuboid_segment_find_local_separating_edge_twoway;
use nalgebra::{Point3, Vector3, Isometry3};
let cube = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
let segment = Segment::new(
Point3::origin(),
Point3::new(0.0, 2.0, 0.0)
);
// Position segment to the right of the cube
let pos12 = Isometry3::translation(2.5, 0.0, 0.0);
let (separation, axis) = cuboid_segment_find_local_separating_edge_twoway(
&cube,
&segment,
&pos12
);
println!("Edge-edge separation: {}", separation);§Usage in Complete SAT
For a complete cuboid-segment collision test, you must also test:
- Cuboid face normals (X, Y, Z axes)
- Segment normal (in 2D) or face normal (for degenerate 3D cases)
- Edge-edge axes (this function, 3D only)