pub fn cuboid_support_map_find_local_separating_normal_oneway<S: SupportMap>(
cube1: &Cuboid,
shape2: &S,
pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)Expand description
Finds the best separating axis by testing the face normals of a cuboid against a support map shape.
This function tests all face normals (X, Y, and Z axes in both positive and negative directions) of the cuboid to find which direction gives the maximum separation from the support map shape.
§Parameters
cube1: The cuboid whose face normals will be testedshape2: Any convex shape implementingSupportMappos12: The position ofshape2relative tocube1
§Returns
A tuple containing:
Real: The maximum separation found among the cuboid’s face normals- Positive: Shapes are separated
- Negative: Shapes are overlapping
Vector<Real>: The face normal direction that gives this separation
§Usage in Complete SAT
This function tests only the face normals of the cuboid. For a complete SAT collision test between a cuboid and another shape, you typically need to:
- Test cuboid’s face normals (this function)
- Test the other shape’s face normals (if applicable)
- Test edge-edge cross products in 3D (if both shapes have edges)
§Example
use parry2d::shape::{Cuboid, Ball};
use parry2d::query::sat::cuboid_support_map_find_local_separating_normal_oneway;
use nalgebra::{Isometry2, Vector2};
let cube = Cuboid::new(Vector2::new(1.0, 1.0));
let sphere = Ball::new(0.5);
// Position sphere to the right of the cube
let pos12 = Isometry2::translation(2.0, 0.0);
let (separation, normal) = cuboid_support_map_find_local_separating_normal_oneway(
&cube,
&sphere,
&pos12
);
if separation > 0.0 {
println!("Shapes separated by {} along normal {}", separation, normal);
} else {
println!("Shapes overlapping by {} along normal {}", -separation, normal);
}§Performance
This function is more efficient than cuboid_support_map_compute_separation_wrt_local_line
for face normals because it can directly compute the separation without testing both directions.
It tests 2×DIM axes (where DIM is 2 or 3).