pub fn segment_cuboid_find_local_separating_normal_oneway(
segment1: &Segment,
shape2: &Cuboid,
pos12: &Isometry<f32>,
) -> (f32, Vector<f32>)Expand description
Finds the best separating axis by testing a segment’s normal against a cuboid (2D only).
In 2D, a segment (line segment) has an associated normal vector perpendicular to the segment. This function tests both directions of this normal to find the maximum separation from the cuboid.
§How It Works
The function treats the segment as a point-with-normal using one of its endpoints (point A)
and delegates to point_cuboid_find_local_separating_normal_oneway.
§Parameters
segment1: The line segment whose normal will be testedshape2: The cuboidpos12: The position of the cuboid relative to the segment
§Returns
A tuple containing:
Real: The separation distance along the segment’s normal- Positive: Shapes are separated
- Negative: Shapes are overlapping
Vector<Real>: The normal direction that gives this separation
§Example
use parry2d::shape::{Segment, Cuboid};
use parry2d::query::sat::segment_cuboid_find_local_separating_normal_oneway;
use nalgebra::{Point2, Vector2, Isometry2};
// Horizontal segment
let segment = Segment::new(
Point2::origin(),
Point2::new(2.0, 0.0)
);
let cuboid = Cuboid::new(Vector2::new(1.0, 1.0));
// Position cuboid above the segment
let pos12 = Isometry2::translation(1.0, 2.5);
let (separation, normal) = segment_cuboid_find_local_separating_normal_oneway(
&segment,
&cuboid,
&pos12
);
println!("Separation along segment normal: {}", separation);§2D Only
This function is only available in 2D. In 3D, segments don’t have a unique normal direction
(there are infinitely many perpendicular directions), so edge-edge cross products are used
instead (see cuboid_segment_find_local_separating_edge_twoway).