pub fn cuboid_cuboid_compute_separation_wrt_local_line(
cuboid1: &Cuboid,
cuboid2: &Cuboid,
pos12: &Pose,
axis1: Vector,
) -> (f32, Vector)Expand description
Computes the separation distance between two cuboids along a given axis.
This function is part of the Separating Axis Theorem (SAT) implementation for cuboid-cuboid collision detection. It projects both cuboids onto the specified axis and computes how far apart they are (positive = separated, negative = overlapping).
§How It Works
- Orients the axis to point from cuboid1 toward cuboid2 (using the translation vector)
- Finds the support points (furthest points) on each cuboid in that direction
- Computes the signed distance between these support points along the axis
§Parameters
cuboid1: The first cuboid (in its local coordinate frame)cuboid2: The second cuboidpos12: The position of cuboid2 relative to cuboid1 (transforms from cuboid2’s space to cuboid1’s space)axis1: The axis direction in cuboid1’s local space to test for separation
§Returns
A tuple containing:
Real: The separation distance along the axis- Positive: Shapes are separated by this distance
- Negative: Shapes are overlapping (penetration depth is the absolute value)
- Zero: Shapes are exactly touching
Vector: The oriented axis direction (pointing from cuboid1 toward cuboid2)
§Example
use parry3d::shape::Cuboid;
use parry3d::query::sat::cuboid_cuboid_compute_separation_wrt_local_line;
use parry3d::math::{Pose, Vector};
let cube1 = Cuboid::new(Vector::splat(1.0));
let cube2 = Cuboid::new(Vector::splat(1.0));
// Position cube2 at (3, 0, 0) relative to cube1
let pos12 = Pose::translation(3.0, 0.0, 0.0);
// Test separation along the X axis
let (separation, _axis) = cuboid_cuboid_compute_separation_wrt_local_line(
&cube1,
&cube2,
&pos12,
Vector::X
);
// Should be separated by 1.0 (distance 3.0 - half_extents 1.0 - 1.0)
assert!(separation > 0.0);