pub fn cuboid_triangle_find_local_separating_edge_twoway(
cube1: &Cuboid,
triangle2: &Triangle,
pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)Expand description
Finds the best separating axis by testing all edge-edge combinations between a cuboid and a triangle (3D only).
In 3D collision detection, when a box and triangle intersect, the contact may occur along an axis perpendicular to an edge from each shape. This function tests all 3×3 = 9 such axes (cross products of cuboid edges with triangle edges) to find the one with maximum separation.
§Parameters
cube1: The cuboid (in its local coordinate frame)triangle2: The trianglepos12: The position of the triangle 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 (penetration depth)
Vector<Real>: The axis direction that gives this separation
§The 9 Axes Tested
The function tests cross products between:
- 3 cuboid edge directions: X, Y, Z (aligned with cuboid axes)
- 3 triangle edge vectors: AB, BC, CA
This gives 3×3 = 9 potential separating axes. Each axis is normalized before testing, and degenerate axes (near-zero length, indicating parallel edges) are skipped.
§Example
use parry3d::shape::{Cuboid, Triangle};
use parry3d::query::sat::cuboid_triangle_find_local_separating_edge_twoway;
use nalgebra::{Point3, Vector3, Isometry3};
let cube = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
let triangle = Triangle::new(
Point3::origin(),
Point3::new(1.0, 0.0, 0.0),
Point3::new(0.0, 1.0, 0.0)
);
// Position triangle near the cube
let pos12 = Isometry3::translation(2.0, 0.0, 0.0);
let (separation, axis) = cuboid_triangle_find_local_separating_edge_twoway(
&cube,
&triangle,
&pos12
);
println!("Edge-edge separation: {} along {}", separation, axis);§Usage in Complete SAT
For a complete cuboid-triangle SAT test, you must also test:
- Cuboid face normals (X, Y, Z axes)
- Triangle face normal (perpendicular to the triangle plane)
- Edge-edge axes (this function)