Function triangle_support_map_find_local_separating_normal_oneway

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

Finds the best separating axis by testing the edge normals of a triangle against a support map shape (2D only).

In 2D, a triangle has three edges, each with an associated outward-pointing normal. This function tests all three edge normals to find which gives the maximum separation from the support map shape.

§Parameters

  • triangle1: The triangle whose edge normals will be tested
  • shape2: Any convex shape implementing SupportMap
  • pos12: The position of shape2 relative to triangle1

§Returns

A tuple containing:

  • Real: The maximum separation found among the triangle’s edge normals
    • Positive: Shapes are separated
    • Negative: Shapes are overlapping
  • Vector<Real>: The edge normal direction that gives this separation

§2D vs 3D

In 2D, triangles are true polygons with edges that have normals. In 3D, triangles are planar surfaces with a face normal (see the 3D version of this function).

§Example

use parry2d::shape::{Triangle, Ball};
use parry2d::query::sat::triangle_support_map_find_local_separating_normal_oneway;
use nalgebra::{Point2, Isometry2};

let triangle = Triangle::new(
    Point2::origin(),
    Point2::new(2.0, 0.0),
    Point2::new(1.0, 2.0)
);
let sphere = Ball::new(0.5);

let pos12 = Isometry2::translation(3.0, 1.0);

let (separation, normal) = triangle_support_map_find_local_separating_normal_oneway(
    &triangle,
    &sphere,
    &pos12
);

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