Function triangle_cuboid_find_local_separating_normal_oneway

Source
pub fn triangle_cuboid_find_local_separating_normal_oneway(
    triangle1: &Triangle,
    shape2: &Cuboid,
    pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)
Expand description

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

In 3D, a triangle is a planar surface with a single face normal (perpendicular to the plane). This function tests both directions of this normal (+normal and -normal) to find the maximum separation from the cuboid.

§How It Works

The function uses the triangle’s face normal and one of its vertices (point A) to represent the triangle as a point-with-normal. It then delegates to point_cuboid_find_local_separating_normal_oneway which efficiently handles this case.

§Parameters

  • triangle1: The triangle whose face normal will be tested
  • shape2: The cuboid
  • pos12: The position of the cuboid 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
  • Vector<Real>: The face normal direction (or its negation) that gives this separation

§Example

use parry3d::shape::{Triangle, Cuboid};
use parry3d::query::sat::triangle_cuboid_find_local_separating_normal_oneway;
use nalgebra::{Point3, Vector3, Isometry3};

// Horizontal 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)
);
let cube = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));

// Position cube above the triangle
let pos12 = Isometry3::translation(1.0, 1.0, 2.0);

let (separation, normal) = triangle_cuboid_find_local_separating_normal_oneway(
    &triangle,
    &cube,
    &pos12
);

println!("Separation along triangle normal: {}", separation);

§2D vs 3D

  • 2D version: Tests three edge normals (one per triangle edge)
  • 3D version (this function): Tests one face normal (perpendicular to triangle plane)