Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Triangle3D Class Reference

Represents a triangle in 3D space defined by three points. More...

#include <point.H>

Collaboration diagram for Aleph::Triangle3D:
[legend]

Classes

struct  BaryCoords
 Structure to hold barycentric coordinates. More...
 

Public Member Functions

 Triangle3D ()=default
 Default constructor.
 
 Triangle3D (const Point3D &p1, const Point3D &p2, const Point3D &p3)
 Constructs a 3D triangle from three vertices.
 
const Point3Dget_p1 () const
 Gets the first vertex of the triangle.
 
const Point3Dget_p2 () const
 Gets the second vertex of the triangle.
 
const Point3Dget_p3 () const
 Gets the third vertex of the triangle.
 
Point3D normal () const
 Computes the normal vector of the triangle's plane.
 
Geom_Number double_area_squared () const
 Calculates twice the squared area of the triangle.
 
Point3D centroid () const
 Computes the centroid (center of mass) of the triangle.
 
bool is_degenerate () const
 Checks if the triangle is degenerate (i.e., its vertices are collinear).
 
BaryCoords barycentric (const Point3D &p) const
 Computes the barycentric coordinates of a point p with respect to this triangle.
 

Private Attributes

Point3D p1_
 
Point3D p2_
 
Point3D p3_
 

Detailed Description

Represents a triangle in 3D space defined by three points.

Definition at line 3358 of file point.H.

Constructor & Destructor Documentation

◆ Triangle3D() [1/2]

Aleph::Triangle3D::Triangle3D ( )
default

Default constructor.

Initializes a degenerate triangle at the origin.

◆ Triangle3D() [2/2]

Aleph::Triangle3D::Triangle3D ( const Point3D p1,
const Point3D p2,
const Point3D p3 
)
inline

Constructs a 3D triangle from three vertices.

Parameters
p1The first vertex.
p2The second vertex.
p3The third vertex.

Definition at line 3372 of file point.H.

Member Function Documentation

◆ barycentric()

BaryCoords Aleph::Triangle3D::barycentric ( const Point3D p) const
inline

Computes the barycentric coordinates of a point p with respect to this triangle.

Parameters
pThe point to find coordinates for.
Returns
A BaryCoords struct containing the coordinates (u, v, w).
Exceptions
std::domain_errorif the triangle is degenerate.

Definition at line 3438 of file point.H.

References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), is_degenerate(), p1_, p2_, p3_, and w.

Referenced by TEST_F(), and TEST_F().

◆ centroid()

Point3D Aleph::Triangle3D::centroid ( ) const
inline

Computes the centroid (center of mass) of the triangle.

Returns
A Point3D representing the centroid.

Definition at line 3407 of file point.H.

References p1_, p2_, and p3_.

Referenced by TEST_F().

◆ double_area_squared()

Geom_Number Aleph::Triangle3D::double_area_squared ( ) const
inline

Calculates twice the squared area of the triangle.

Returns
2 * area^2, which is equal to normal().norm_squared() / 2.

Definition at line 3398 of file point.H.

References Aleph::Point3D::norm_squared(), and normal().

Referenced by TEST_F().

◆ get_p1()

const Point3D & Aleph::Triangle3D::get_p1 ( ) const
inline

Gets the first vertex of the triangle.

Definition at line 3376 of file point.H.

References p1_.

Referenced by Aleph::operator<<().

◆ get_p2()

const Point3D & Aleph::Triangle3D::get_p2 ( ) const
inline

Gets the second vertex of the triangle.

Definition at line 3378 of file point.H.

References p2_.

Referenced by Aleph::operator<<().

◆ get_p3()

const Point3D & Aleph::Triangle3D::get_p3 ( ) const
inline

Gets the third vertex of the triangle.

Definition at line 3380 of file point.H.

References p3_.

Referenced by Aleph::operator<<().

◆ is_degenerate()

bool Aleph::Triangle3D::is_degenerate ( ) const
inline

Checks if the triangle is degenerate (i.e., its vertices are collinear).

Returns
true if the area is zero, false otherwise.

Definition at line 3416 of file point.H.

References Aleph::Point3D::norm_squared(), and normal().

Referenced by barycentric(), TEST_F(), and TEST_F().

◆ normal()

Point3D Aleph::Triangle3D::normal ( ) const
inline

Computes the normal vector of the triangle's plane.

The normal is calculated as (p2-p1) x (p3-p1). Its magnitude is twice the triangle's area. The direction depends on the winding order of the vertices.

Returns
A Point3D representing the normal vector (not normalized).

Definition at line 3389 of file point.H.

References Aleph::Point3D::cross(), p1_, p2_, and p3_.

Referenced by double_area_squared(), is_degenerate(), and TEST_F().

Member Data Documentation

◆ p1_

Point3D Aleph::Triangle3D::p1_
private

Definition at line 3360 of file point.H.

Referenced by barycentric(), centroid(), get_p1(), and normal().

◆ p2_

Point3D Aleph::Triangle3D::p2_
private

Definition at line 3360 of file point.H.

Referenced by barycentric(), centroid(), get_p2(), and normal().

◆ p3_

Point3D Aleph::Triangle3D::p3_
private

Definition at line 3360 of file point.H.

Referenced by barycentric(), centroid(), get_p3(), and normal().


The documentation for this class was generated from the following file: