#[repr(C)]pub struct Triangle {
pub a: Point<f32>,
pub b: Point<f32>,
pub c: Point<f32>,
}Expand description
A triangle shape defined by three vertices.
A triangle is one of the most fundamental shapes in computational geometry. It’s the simplest 2D polygon and the building block for triangle meshes.
§Structure
- a, b, c: The three vertices of the triangle
- Edges: AB (from a to b), BC (from b to c), CA (from c to a)
- Orientation: Counter-clockwise (CCW) is the standard convention
§Properties
- Convex: Always convex
- 2D/3D: Can be used in both dimensions
- In 2D: A filled triangular region with area
- In 3D: A flat surface embedded in 3D space (zero volume)
§Orientation Convention
Triangles are typically defined with counter-clockwise vertex order:
- Looking at the triangle from the “front”, vertices go a → b → c in CCW order
- The normal vector (3D) points toward the observer
- Right-hand rule: Curl fingers from a→b→c, thumb points along normal
§Use Cases
- Mesh building block: Fundamental unit of triangle meshes
- Simple collision shapes: Fast collision detection
- Terrain representation: Ground planes and surfaces
- Testing and debugging: Simple shape for verification
§Example
use parry3d::shape::Triangle;
use nalgebra::Point3;
// Create a right triangle in the XY plane
let triangle = Triangle::new(
Point3::origin(), // a: origin
Point3::new(3.0, 0.0, 0.0), // b: along +X
Point3::new(0.0, 4.0, 0.0) // c: along +Y
);
// Area of 3-4-5 right triangle is 6.0
assert_eq!(triangle.area(), 6.0);
// Check if a point is inside
let inside = Point3::new(1.0, 1.0, 0.0);
assert!(triangle.contains_point(&inside));Fields§
§a: Point<f32>The first vertex of the triangle.
b: Point<f32>The second vertex of the triangle.
c: Point<f32>The third vertex of the triangle.
Implementations§
Source§impl Triangle
impl Triangle
Sourcepub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere
pub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere
Computes the world-space bounding sphere of this triangle, transformed by pos.
Sourcepub fn local_bounding_sphere(&self) -> BoundingSphere
pub fn local_bounding_sphere(&self) -> BoundingSphere
Computes the local-space bounding sphere of this triangle.
Source§impl Triangle
impl Triangle
Sourcepub fn new(a: Point<f32>, b: Point<f32>, c: Point<f32>) -> Triangle
pub fn new(a: Point<f32>, b: Point<f32>, c: Point<f32>) -> Triangle
Creates a triangle from three vertices.
§Arguments
a- The first vertexb- The second vertexc- The third vertex
§Convention
For proper normal calculation and consistent collision detection, vertices should be ordered counter-clockwise when viewed from the “front” side.
§Example
use parry3d::shape::Triangle;
use nalgebra::Point3;
// Create a triangle in the XY plane
let tri = Triangle::new(
Point3::origin(),
Point3::new(1.0, 0.0, 0.0),
Point3::new(0.0, 1.0, 0.0)
);
assert_eq!(tri.area(), 0.5);Sourcepub fn from_array(arr: &[Point<f32>; 3]) -> &Triangle
pub fn from_array(arr: &[Point<f32>; 3]) -> &Triangle
Creates the reference to a triangle from the reference to an array of three points.
Sourcepub fn vertices(&self) -> &[Point<f32>; 3]
pub fn vertices(&self) -> &[Point<f32>; 3]
Reference to an array containing the three vertices of this triangle.
Sourcepub fn transformed(&self, m: &Isometry<f32>) -> Self
pub fn transformed(&self, m: &Isometry<f32>) -> Self
Returns a new triangle with vertices transformed by m.
Sourcepub fn edges_scaled_directions(&self) -> [Vector<f32>; 3]
pub fn edges_scaled_directions(&self) -> [Vector<f32>; 3]
The three edges scaled directions of this triangle: [B - A, C - B, A - C].
Sourcepub fn local_support_edge_segment(&self, dir: Vector<f32>) -> Segment
pub fn local_support_edge_segment(&self, dir: Vector<f32>) -> Segment
Return the edge segment of this cuboid with a normal cone containing
a direction that that maximizes the dot product with local_dir.
Sourcepub fn support_face(&self, dir: Vector<f32>) -> PolygonalFeature
pub fn support_face(&self, dir: Vector<f32>) -> PolygonalFeature
Return the face of this triangle with a normal that maximizes
the dot product with dir.
Sourcepub fn extents_on_dir(&self, dir: &Unit<Vector<f32>>) -> (f32, f32)
pub fn extents_on_dir(&self, dir: &Unit<Vector<f32>>) -> (f32, f32)
Computes the extents of this triangle on the given direction.
This computes the min and max values of the dot products between each
vertex of this triangle and dir.
Sourcepub fn unit_angular_inertia(&self) -> f32
pub fn unit_angular_inertia(&self) -> f32
Computes the unit angular inertia of this triangle.
Sourcepub fn circumcircle(&self) -> (Point<f32>, f32)
pub fn circumcircle(&self) -> (Point<f32>, f32)
The circumcircle of this triangle.
Sourcepub fn contains_point(&self, p: &Point<f32>) -> bool
pub fn contains_point(&self, p: &Point<f32>) -> bool
Tests if a point is inside of this triangle.
Sourcepub fn orientation(&self, epsilon: f32) -> TriangleOrientation
pub fn orientation(&self, epsilon: f32) -> TriangleOrientation
The orientation of the triangle, based on its signed area.
Returns TriangleOrientation::Degenerate if the triangle’s area is
smaller than epsilon.
Sourcepub fn orientation2d(
a: &Point2<f32>,
b: &Point2<f32>,
c: &Point2<f32>,
epsilon: f32,
) -> TriangleOrientation
pub fn orientation2d( a: &Point2<f32>, b: &Point2<f32>, c: &Point2<f32>, epsilon: f32, ) -> TriangleOrientation
The orientation of the 2D triangle, based on its signed area.
Returns TriangleOrientation::Degenerate if the triangle’s area is
smaller than epsilon.
Sourcepub fn angle_closest_to_90(&self) -> usize
pub fn angle_closest_to_90(&self) -> usize
Find the index of a vertex in this triangle, such that the two edges incident in that vertex form the angle closest to 90 degrees in the triangle.
Trait Implementations§
Source§impl PointQuery for Triangle
impl PointQuery for Triangle
Source§fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection
fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection
self. Read moreSource§fn project_local_point_and_get_feature(
&self,
pt: &Point<f32>,
) -> (PointProjection, FeatureId)
fn project_local_point_and_get_feature( &self, pt: &Point<f32>, ) -> (PointProjection, FeatureId)
self and returns the id of the
feature the point was projected on.Source§fn project_local_point_with_max_dist(
&self,
pt: &Point<f32>,
solid: bool,
max_dist: f32,
) -> Option<PointProjection>
fn project_local_point_with_max_dist( &self, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>
Source§fn project_point_with_max_dist(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
max_dist: f32,
) -> Option<PointProjection>
fn project_point_with_max_dist( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>
self transformed by m, unless the projection lies further than the given max distance.Source§fn distance_to_local_point(&self, pt: &Point<f32>, solid: bool) -> f32
fn distance_to_local_point(&self, pt: &Point<f32>, solid: bool) -> f32
self.Source§fn contains_local_point(&self, pt: &Point<f32>) -> bool
fn contains_local_point(&self, pt: &Point<f32>) -> bool
self.Source§fn project_point(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
) -> PointProjection
fn project_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> PointProjection
self transformed by m.Source§fn distance_to_point(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
) -> f32
fn distance_to_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> f32
self transformed by m.Source§fn project_point_and_get_feature(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
) -> (PointProjection, FeatureId)
fn project_point_and_get_feature( &self, m: &Isometry<f32>, pt: &Point<f32>, ) -> (PointProjection, FeatureId)
self transformed by m and returns the id of the
feature the point was projected on.Source§impl PointQueryWithLocation for Triangle
impl PointQueryWithLocation for Triangle
Source§type Location = TrianglePointLocation
type Location = TrianglePointLocation
Source§fn project_local_point_and_get_location(
&self,
pt: &Point<f32>,
solid: bool,
) -> (PointProjection, Self::Location)
fn project_local_point_and_get_location( &self, pt: &Point<f32>, solid: bool, ) -> (PointProjection, Self::Location)
self.Source§fn project_point_and_get_location(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
) -> (PointProjection, Self::Location)
fn project_point_and_get_location( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> (PointProjection, Self::Location)
self transformed by m.Source§fn project_local_point_and_get_location_with_max_dist(
&self,
pt: &Point<f32>,
solid: bool,
max_dist: f32,
) -> Option<(PointProjection, Self::Location)>
fn project_local_point_and_get_location_with_max_dist( &self, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<(PointProjection, Self::Location)>
self, with a maximum projection distance.Source§impl PolygonalFeatureMap for Triangle
impl PolygonalFeatureMap for Triangle
Source§fn local_support_feature(
&self,
dir: &Unit<Vector<f32>>,
out_feature: &mut PolygonalFeature,
)
fn local_support_feature( &self, dir: &Unit<Vector<f32>>, out_feature: &mut PolygonalFeature, )
self towards the dir.Source§fn is_convex_polyhedron(&self) -> bool
fn is_convex_polyhedron(&self) -> bool
ConvexPolyhedron?Source§impl RayCast for Triangle
impl RayCast for Triangle
Source§fn cast_local_ray_and_get_normal(
&self,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<RayIntersection>
fn cast_local_ray_and_get_normal( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>
Source§fn cast_local_ray(
&self,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<f32>
fn cast_local_ray( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>
Source§fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool
fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool
Source§fn cast_ray(
&self,
m: &Isometry<f32>,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<f32>
fn cast_ray( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>
Source§fn cast_ray_and_get_normal(
&self,
m: &Isometry<f32>,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<RayIntersection>
fn cast_ray_and_get_normal( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>
Source§impl Shape for Triangle
impl Shape for Triangle
Source§fn scale_dyn(
&self,
scale: &Vector<f32>,
_num_subdivisions: u32,
) -> Option<Box<dyn Shape>>
fn scale_dyn( &self, scale: &Vector<f32>, _num_subdivisions: u32, ) -> Option<Box<dyn Shape>>
scale into a boxed trait-object. Read moreSource§fn compute_local_aabb(&self) -> Aabb
fn compute_local_aabb(&self) -> Aabb
Aabb of this shape.Source§fn compute_local_bounding_sphere(&self) -> BoundingSphere
fn compute_local_bounding_sphere(&self) -> BoundingSphere
Source§fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb
fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb
Aabb of this shape with the given position.Source§fn mass_properties(&self, _density: f32) -> MassProperties
fn mass_properties(&self, _density: f32) -> MassProperties
Source§fn shape_type(&self) -> ShapeType
fn shape_type(&self) -> ShapeType
Source§fn as_typed_shape(&self) -> TypedShape<'_>
fn as_typed_shape(&self) -> TypedShape<'_>
fn ccd_thickness(&self) -> f32
fn ccd_angular_thickness(&self) -> f32
Source§fn as_support_map(&self) -> Option<&dyn SupportMap>
fn as_support_map(&self) -> Option<&dyn SupportMap>
Source§fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>
fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>
Source§fn feature_normal_at_point(
&self,
_feature: FeatureId,
_point: &Point<f32>,
) -> Option<Unit<Vector<f32>>>
fn feature_normal_at_point( &self, _feature: FeatureId, _point: &Point<f32>, ) -> Option<Unit<Vector<f32>>>
Source§fn clone_box(&self) -> Box<dyn Shape>
fn clone_box(&self) -> Box<dyn Shape>
clone_dynSource§fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere
fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere
fn as_composite_shape(&self) -> Option<&dyn CompositeShape>
Source§impl SupportMap for Triangle
impl SupportMap for Triangle
Source§fn local_support_point(&self, dir: &Vector<f32>) -> Point<f32>
fn local_support_point(&self, dir: &Vector<f32>) -> Point<f32>
impl Copy for Triangle
impl StructuralPartialEq for Triangle
Auto Trait Implementations§
impl Freeze for Triangle
impl RefUnwindSafe for Triangle
impl Send for Triangle
impl Sync for Triangle
impl Unpin for Triangle
impl UnwindSafe for Triangle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.