Function triangle_segment_find_local_separating_normal_oneway

Source
pub fn triangle_segment_find_local_separating_normal_oneway(
    triangle1: &Triangle,
    segment2: &Segment,
    pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)
Expand description

Finds the best separating axis by testing a triangle’s face normal against a segment (3D only).

In 3D, a triangle has a face normal (perpendicular to its plane). This function tests both directions of this normal (+normal and -normal) to find the maximum separation from the segment.

§How It Works

The function computes support points on the segment in both the positive and negative normal directions, then measures which direction gives greater separation from the triangle’s surface.

§Parameters

  • triangle1: The triangle whose face normal will be tested
  • segment2: The line segment
  • pos12: The position of the segment relative to the triangle

§Returns

A tuple containing:

  • Real: The separation distance along the triangle’s face normal
    • Positive: Shapes are separated
    • Negative: Shapes are overlapping
    • Very negative if the triangle has no normal (degenerate triangle)
  • Vector<Real>: The face normal direction (or its negation) that gives this separation

§Degenerate Triangles

If the triangle is degenerate (all three points are collinear), it has no valid normal. In this case, the function returns -Real::MAX for separation and a zero vector for the normal.

§Example

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

// Triangle in the XY plane
let triangle = Triangle::new(
    Point3::origin(),
    Point3::new(2.0, 0.0, 0.0),
    Point3::new(1.0, 2.0, 0.0)
);

// Vertical segment above the triangle
let segment = Segment::new(
    Point3::new(1.0, 1.0, 1.0),
    Point3::new(1.0, 1.0, 3.0)
);

let pos12 = Isometry3::identity();

let (separation, normal) = triangle_segment_find_local_separating_normal_oneway(
    &triangle,
    &segment,
    &pos12
);

if separation > 0.0 {
    println!("Separated by {} along triangle normal", separation);
}

§Usage in Complete SAT

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

  1. Triangle face normal (this function)
  2. Segment normal (in 2D) or edge-edge axes (in 3D)
  3. Edge-edge cross products (see segment_triangle_find_local_separating_edge_twoway)