cuboid_support_map_find_local_separating_edge_twoway

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],
    pos12: &Pose,
) -> (f32, Vector)
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: 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 parry3d::math::{Pose, Vector};

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

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

// Compute edge cross products
let capsule_dir = Vector::Y; // capsule's axis direction
let axes = [
    Vector::X.cross(capsule_dir), // cube X × capsule axis
    Vector::Y.cross(capsule_dir), // cube Y × capsule axis
    Vector::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