Function segment_triangle_find_local_separating_edge_twoway

Source
pub fn segment_triangle_find_local_separating_edge_twoway(
    segment1: &Segment,
    triangle2: &Triangle,
    pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)
Expand description

Finds the best separating axis by testing edge-edge combinations between a segment and a triangle (3D only).

In 3D, when a line segment and triangle collide, the contact might occur along an axis perpendicular to both the segment and one of the triangle’s edges. This function tests all such axes (cross products) to find the one with maximum separation.

§Parameters

  • segment1: The line segment
  • triangle2: The triangle
  • pos12: The position of the triangle relative to the segment

§Returns

A tuple containing:

  • Real: The maximum separation found across all edge-edge axes
    • Positive: Shapes are separated
    • Negative: Shapes are overlapping
  • Vector<Real>: The axis direction that gives this separation

§The Axes Tested

The function computes cross products between:

  • The segment’s direction (B - A)
  • Each of the 3 triangle edges (AB, BC, CA)

This gives 3 base axes. The function tests both each axis and its negation (6 total), finding which gives the maximum separation.

§Example

use parry3d::shape::{Segment, Triangle};
use parry3d::query::sat::segment_triangle_find_local_separating_edge_twoway;
use nalgebra::{Point3, Isometry3};

let segment = Segment::new(
    Point3::origin(),
    Point3::new(0.0, 0.0, 2.0)
);

let triangle = Triangle::new(
    Point3::new(1.0, 0.0, 1.0),
    Point3::new(3.0, 0.0, 1.0),
    Point3::new(2.0, 2.0, 1.0)
);

let pos12 = Isometry3::identity();

let (separation, axis) = segment_triangle_find_local_separating_edge_twoway(
    &segment,
    &triangle,
    &pos12
);

if separation > 0.0 {
    println!("Separated by {} along edge-edge axis", separation);
}

§Implementation Details

  • Axes with near-zero length (parallel edges) are skipped
  • The function uses support_map_support_map_compute_separation to compute the actual separation along each axis
  • Both positive and negative directions are tested for each cross product

§Usage in Complete SAT

For a complete segment-triangle collision test, you must also test:

  1. Triangle face normal (triangle_segment_find_local_separating_normal_oneway)
  2. Segment-specific axes (depends on whether the segment has associated normals)
  3. Edge-edge cross products (this function)