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

A non-degenerate triangle defined by three points. More...

#include <point.H>

Inheritance diagram for Aleph::Triangle:
[legend]
Collaboration diagram for Aleph::Triangle:
[legend]

Public Member Functions

 Triangle (Point p1, Point p2, Point p3)
 Constructs a triangle from three points.
 
 Triangle (Point p, const Segment &s)
 Constructs a triangle from a point and a segment.
 
 Triangle (const Segment &s, Point p)
 Constructs a triangle from a segment and a point.
 
Geom_Number area () const
 Calculates the unsigned area of the triangle.
 
bool is_clockwise () const
 Checks if the triangle vertices are ordered clockwise.
 
const Pointhighest_point () const
 Gets the vertex with the largest y-coordinate.
 
const Pointlowest_point () const
 Gets the vertex with the smallest y-coordinate.
 
const Pointleftmost_point () const
 Gets the vertex with the smallest x-coordinate.
 
const Pointrightmost_point () const
 Gets the vertex with the largest x-coordinate.
 
const Pointget_p1 () const
 Gets the first vertex.
 
const Pointget_p2 () const
 Gets the second vertex.
 
const Pointget_p3 () const
 Gets the third vertex.
 
bool operator== (const Triangle &t) const noexcept
 Checks for equality between two triangles.
 
bool operator!= (const Triangle &t) const noexcept
 Checks for inequality between two triangles.
 
Point centroid () const
 Computes the centroid (center of mass) of the triangle.
 
Geom_Number perimeter () const
 Computes the perimeter of the triangle.
 
Point circumcenter () const
 Computes the circumcenter of the triangle.
 
Point incenter () const
 Computes the incenter of the triangle.
 
std::array< Segment, 3 > edges () const
 Gets the three edges of the triangle.
 
bool contains (const Point &p) const
 Checks if a point lies strictly inside this triangle.
 
Segment intersection_with (const Segment &s) const
 Computes the intersection segment between this triangle and a segment.
 
- Public Member Functions inherited from Aleph::Geom_Object
 Geom_Object ()=default
 
virtual ~Geom_Object ()=default
 

Private Attributes

Point p1_
 
Point p2_
 
Point p3_
 
Geom_Number area_
 

Friends

class Point
 
class Segment
 

Detailed Description

A non-degenerate triangle defined by three points.

Provides basic geometric properties and predicates for a triangle, such as area, orientation, and special centers (centroid, circumcenter, incenter). Used by polygon triangulation and other geometric algorithms.

Definition at line 1477 of file point.H.

Constructor & Destructor Documentation

◆ Triangle() [1/3]

Aleph::Triangle::Triangle ( Point  p1,
Point  p2,
Point  p3 
)
inline

Constructs a triangle from three points.

Parameters
p1The first vertex.
p2The second vertex.
p3The third vertex.
Exceptions
std::domain_errorif the three points are collinear.

Definition at line 1494 of file point.H.

References ah_domain_error_if, area_, Aleph::area_of_parallelogram(), p1_, p2_, and p3_.

◆ Triangle() [2/3]

Aleph::Triangle::Triangle ( Point  p,
const Segment s 
)
inline

Constructs a triangle from a point and a segment.

Parameters
pThe first vertex.
sThe segment defining the other two vertices.
Exceptions
std::domain_errorif the three points are collinear.

Definition at line 1508 of file point.H.

References ah_domain_error_if, area_, Aleph::area_of_parallelogram(), p1_, p2_, and p3_.

◆ Triangle() [3/3]

Aleph::Triangle::Triangle ( const Segment s,
Point  p 
)
inline

Constructs a triangle from a segment and a point.

Parameters
sThe segment defining the first two vertices.
pThe third vertex.
Exceptions
std::domain_errorif the three points are collinear.

Definition at line 1521 of file point.H.

References ah_domain_error_if, area_, Aleph::area_of_parallelogram(), p1_, p2_, and p3_.

Member Function Documentation

◆ area()

Geom_Number Aleph::Triangle::area ( ) const
inline

Calculates the unsigned area of the triangle.

Returns
The area of the triangle.

Definition at line 1532 of file point.H.

References abs(), and area_.

◆ centroid()

Point Aleph::Triangle::centroid ( ) const
inline

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

Returns
A Point representing the centroid.

Definition at line 1622 of file point.H.

References p1_, p2_, and p3_.

◆ circumcenter()

Point Aleph::Triangle::circumcenter ( ) const
inline

Computes the circumcenter of the triangle.

The circumcenter is the intersection point of the perpendicular bisectors of the edges and is equidistant from the three vertices.

Returns
A Point representing the circumcenter.
Exceptions
std::domain_errorif the triangle is degenerate (collinear vertices).

Definition at line 1643 of file point.H.

References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Point::get_x(), Aleph::Point::get_y(), p1_, p2_, p3_, and y1().

◆ contains()

bool Aleph::Triangle::contains ( const Point p) const
inline

Checks if a point lies strictly inside this triangle.

This is done by checking if the point is on the same side of all three edges. The result depends on the triangle's orientation.

Parameters
pThe point to check.
Returns
true if the point is strictly inside, false if it is on an edge or outside.

Definition at line 1706 of file point.H.

References Aleph::and, is_clockwise(), Aleph::Point::is_left_of(), Aleph::Point::is_to_right_from(), p1_, p2_, and p3_.

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

◆ edges()

std::array< Segment, 3 > Aleph::Triangle::edges ( ) const
inline

Gets the three edges of the triangle.

Returns
A std::array of 3 Segments in the order (p1,p2), (p2,p3), (p3,p1).

Definition at line 1693 of file point.H.

References p1_, p2_, p3_, and Segment.

◆ get_p1()

◆ get_p2()

◆ get_p3()

◆ highest_point()

const Point & Aleph::Triangle::highest_point ( ) const
inline

Gets the vertex with the largest y-coordinate.

Returns
A const reference to the highest vertex.

Definition at line 1550 of file point.H.

References Aleph::Point::get_y(), max(), p1_, p2_, and p3_.

Referenced by Aleph::Tikz_Plane::bbox_of().

◆ incenter()

Point Aleph::Triangle::incenter ( ) const
inline

Computes the incenter of the triangle.

The incenter is the intersection point of the angle bisectors and is the center of the triangle's incircle.

Returns
A Point representing the incenter.
Exceptions
std::domain_errorif the triangle is degenerate.

Definition at line 1678 of file point.H.

References ah_domain_error_if, Aleph::Point::distance_to(), p1_, p2_, p3_, and Aleph::sum().

◆ intersection_with()

Segment Aleph::Triangle::intersection_with ( const Segment s) const
inline

Computes the intersection segment between this triangle and a segment.

Parameters
sThe segment to intersect with.
Returns
The intersection Segment.
See also
Segment::intersection_with(const Triangle &)

Definition at line 1723 of file point.H.

References Aleph::Segment::intersection_with().

◆ is_clockwise()

bool Aleph::Triangle::is_clockwise ( ) const
inline

Checks if the triangle vertices are ordered clockwise.

Returns
true if the vertex order (p1, p2, p3) is clockwise, false otherwise.

Definition at line 1541 of file point.H.

References area_.

Referenced by contains().

◆ leftmost_point()

const Point & Aleph::Triangle::leftmost_point ( ) const
inline

Gets the vertex with the smallest x-coordinate.

Returns
A const reference to the leftmost vertex.

Definition at line 1570 of file point.H.

References Aleph::Point::get_x(), min(), p1_, p2_, and p3_.

Referenced by Aleph::Tikz_Plane::bbox_of().

◆ lowest_point()

const Point & Aleph::Triangle::lowest_point ( ) const
inline

Gets the vertex with the smallest y-coordinate.

Returns
A const reference to the lowest vertex.

Definition at line 1560 of file point.H.

References Aleph::Point::get_y(), min(), p1_, p2_, and p3_.

Referenced by Aleph::Tikz_Plane::bbox_of().

◆ operator!=()

bool Aleph::Triangle::operator!= ( const Triangle t) const
inlinenoexcept

Checks for inequality between two triangles.

Parameters
tThe other triangle to compare.
Returns
true if the triangles do not share the same three vertices.

Definition at line 1613 of file point.H.

References Aleph::divide_and_conquer_partition_dp().

◆ operator==()

bool Aleph::Triangle::operator== ( const Triangle t) const
inlinenoexcept

Checks for equality between two triangles.

Note
Triangles are equal if they have the same set of three vertices, regardless of their order.
Parameters
tThe other triangle to compare.
Returns
true if the triangles are composed of the same three points.

Definition at line 1600 of file point.H.

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

◆ perimeter()

Geom_Number Aleph::Triangle::perimeter ( ) const
inline

Computes the perimeter of the triangle.

Returns
The sum of the lengths of the three edges.

Definition at line 1631 of file point.H.

References Aleph::Point::distance_to(), p1_, p2_, and p3_.

◆ rightmost_point()

const Point & Aleph::Triangle::rightmost_point ( ) const
inline

Gets the vertex with the largest x-coordinate.

Returns
A const reference to the rightmost vertex.

Definition at line 1580 of file point.H.

References Aleph::Point::get_x(), max(), p1_, p2_, and p3_.

Referenced by Aleph::Tikz_Plane::bbox_of().

Friends And Related Symbol Documentation

◆ Point

friend class Point
friend

Definition at line 1479 of file point.H.

◆ Segment

Definition at line 1480 of file point.H.

Referenced by edges().

Member Data Documentation

◆ area_

Geom_Number Aleph::Triangle::area_
private

Definition at line 1484 of file point.H.

Referenced by Triangle(), Triangle(), Triangle(), area(), and is_clockwise().

◆ p1_

◆ p2_

◆ p3_


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