Function cuboid_cuboid_compute_separation_wrt_local_line

Source
pub fn cuboid_cuboid_compute_separation_wrt_local_line(
    cuboid1: &Cuboid,
    cuboid2: &Cuboid,
    pos12: &Isometry<f32>,
    axis1: &Vector<f32>,
) -> (f32, Vector<f32>)
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

  1. Orients the axis to point from cuboid1 toward cuboid2 (using the translation vector)
  2. Finds the support points (furthest points) on each cuboid in that direction
  3. Computes the signed distance between these support points along the axis

§Parameters

  • cuboid1: The first cuboid (in its local coordinate frame)
  • cuboid2: The second cuboid
  • pos12: 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<Real>: 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 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));

// Position cube2 at (3, 0, 0) relative to cube1
let pos12 = Isometry3::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,
    &Vector3::x()
);

// Should be separated by 1.0 (distance 3.0 - half_extents 1.0 - 1.0)
assert!(separation > 0.0);