pub fn cuboid_cuboid_find_local_separating_normal_oneway(
cuboid1: &Cuboid,
cuboid2: &Cuboid,
pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)Expand description
Finds the best separating axis by testing the face normals of the first cuboid.
This function tests the face normals (X, Y, Z axes in 2D/3D) of cuboid1 to find which
direction gives the maximum separation between the two cuboids. This is the “one-way” test
that only considers faces from one cuboid.
§Why “One-Way”?
For a complete SAT test between two cuboids, you need to test:
- Face normals from cuboid1 (this function)
- Face normals from cuboid2 (call this function again with swapped arguments)
- Edge-edge cross products in 3D (
cuboid_cuboid_find_local_separating_edge_twoway)
By testing only one shape’s normals at a time, the implementation can be more efficient and reusable.
§Parameters
cuboid1: The cuboid whose face normals will be testedcuboid2: The other cuboidpos12: The position of cuboid2 relative to cuboid1
§Returns
A tuple containing:
Real: The maximum separation found among cuboid1’s face normals- Positive: Shapes are separated by at least this distance
- Negative: Shapes are overlapping (penetration)
Vector<Real>: The face normal direction that gives this separation
§Example
use parry2d::shape::Cuboid;
use parry2d::query::sat::cuboid_cuboid_find_local_separating_normal_oneway;
use nalgebra::{Isometry2, Vector2};
let rect1 = Cuboid::new(Vector2::new(1.0, 1.0));
let rect2 = Cuboid::new(Vector2::new(0.5, 0.5));
// Position rect2 to the right of rect1
let pos12 = Isometry2::translation(2.5, 0.0);
// Test rect1's face normals (X and Y axes)
let (sep1, normal1) = cuboid_cuboid_find_local_separating_normal_oneway(
&rect1, &rect2, &pos12
);
// Test rect2's face normals by swapping arguments and inverting the transform
let (sep2, normal2) = cuboid_cuboid_find_local_separating_normal_oneway(
&rect2, &rect1, &pos12.inverse()
);
// The maximum separation indicates if shapes collide
let max_separation = sep1.max(sep2);
if max_separation > 0.0 {
println!("Shapes are separated!");
}§Algorithm Details
For each axis (X, Y, and Z in 3D):
- Computes the support point on cuboid2 in the negative axis direction
- Transforms it to cuboid1’s space
- Measures the signed distance from cuboid1’s boundary
- Tracks the axis with maximum separation