pub fn cuboid_cuboid_find_local_separating_edge_twoway(
cuboid1: &Cuboid,
cuboid2: &Cuboid,
pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)Expand description
Finds the best separating axis by testing all edge-edge combinations between two cuboids.
In 3D, edge-edge contact is common when two boxes collide. This function tests all possible axes formed by the cross product of edges from each cuboid to find the axis with maximum separation (or minimum penetration).
§Why Test Edge Cross Products?
When two 3D convex polyhedra collide, the separating axis (if one exists) must be either:
- A face normal from one shape
- A face normal from the other shape
- Perpendicular to an edge from each shape (the cross product of the edges)
This function handles case 3. For two cuboids, there are 3 edges per cuboid (aligned with X, Y, Z), giving 3 × 3 = 9 possible edge pair combinations to test.
§Parameters
cuboid1: The first cuboid (in its local coordinate frame)cuboid2: The second cuboidpos12: The position of cuboid2 relative to cuboid1
§Returns
A tuple containing:
Real: The best (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
§Example
use parry3d::shape::Cuboid;
use parry3d::query::sat::cuboid_cuboid_find_local_separating_edge_twoway;
use nalgebra::{Isometry3, Vector3};
let cube1 = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
let cube2 = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
// Rotate and position cube2 so edge-edge contact is likely
let pos12 = Isometry3::translation(2.0, 2.0, 0.0);
let (separation, _axis) = cuboid_cuboid_find_local_separating_edge_twoway(
&cube1,
&cube2,
&pos12
);
if separation > 0.0 {
println!("Separated by {} along an edge-edge axis", separation);
}§Note
This function only tests edge-edge axes. For a complete SAT test, you must also test
face normals using cuboid_cuboid_find_local_separating_normal_oneway.