Function cuboid_support_map_find_local_separating_edge_twoway

Source
pub fn cuboid_support_map_find_local_separating_edge_twoway(
    cube1: &Cuboid,
    shape2: &impl SupportMap,
    axes: &[Vector<f32>],
    pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)
Expand description

Finds the best separating axis by testing edge-edge combinations between a cuboid and a support map shape.

This function is used in 3D SAT implementations where edge-edge contact is possible. It tests a precomputed set of axes (typically cross products of edges from both shapes) to find the axis with maximum separation.

§Parameters

  • cube1: The cuboid
  • shape2: Any convex shape implementing SupportMap
  • axes: A slice of axis directions to test (not necessarily unit length)
  • pos12: The position of shape2 relative to cube1

§Returns

A tuple containing:

  • Real: The maximum separation found across all tested axes
    • Positive: Shapes are separated
    • Negative: Shapes are overlapping (minimum penetration)
  • Vector<Real>: The axis direction that gives this separation (normalized)

§Why Precomputed Axes?

The caller typically computes the candidate axes as cross products of edges:

  • Cuboid has 3 edge directions (X, Y, Z)
  • The other shape’s edges depend on its geometry
  • Cross products of these edges give potential separating axes

This function handles the actual separation testing for those precomputed axes.

§Example

use parry3d::shape::{Cuboid, Capsule};
use parry3d::query::sat::cuboid_support_map_find_local_separating_edge_twoway;
use nalgebra::{Isometry3, Vector3, Point3};

let cube = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
let capsule = Capsule::new(Point3::new(0.0, -1.0, 0.0), Point3::new(0.0, 1.0, 0.0), 0.5);

// Position capsule near the cube
let pos12 = Isometry3::translation(2.0, 0.0, 0.0);

// Compute edge cross products
let capsule_dir = Vector3::y(); // capsule's axis direction
let axes = [
    Vector3::x().cross(&capsule_dir), // cube X × capsule axis
    Vector3::y().cross(&capsule_dir), // cube Y × capsule axis
    Vector3::z().cross(&capsule_dir), // cube Z × capsule axis
];

let (separation, axis) = cuboid_support_map_find_local_separating_edge_twoway(
    &cube,
    &capsule,
    &axes,
    &pos12
);

println!("Best edge-edge separation: {} along {}", separation, axis);

§Implementation Details

  • Axes with near-zero length are skipped (they represent parallel or degenerate edges)
  • Each axis is normalized before computing separation
  • The function tests both positive and negative directions of each axis using cuboid_support_map_compute_separation_wrt_local_line