UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils::Segment2D< Real > Class Template Reference

A class representing a 2D line segment defined by two endpoints. More...

#include <Utils_GG2D.hh>

Public Member Functions

 Segment2D ()=default
 Default constructor for the segment.
 
 Segment2D (Segment2D< Real > const &S)
 Copy constructor for the segment.
 
 Segment2D (Point2D< Real > const &A, Point2D< Real > const &B)
 Constructor to create a segment from two points.
 
void setup (Point2D< Real > const &A, Point2D< Real > const &B)
 Setup the endpoints of the segment using Point2D objects.
 
void setup (Real const A[], Real const B[])
 Setup the endpoints of the segment using arrays.
 
bool projection (Point2D< Real > const &P, Real &s) const
 Projects a point onto the segment.
 
Point2D< Real > projection (Point2D< Real > const &P, Real &s, Real &t) const
 Projects a point onto the segment and returns the projected point.
 
Point2D< Real > eval (Real &s) const
 Evaluates the segment at a given parameter s.
 
Point2D< Real > eval (Real &s, Real &t) const
 Evaluates the segment based on two parameters s and t.
 
Point2D< Real > const & Pa () const
 Returns the first endpoint of the segment.
 
Point2D< Real > const & Pb () const
 Returns the second endpoint of the segment.
 
void bbox (Point2D< Real > &pmin, Point2D< Real > &pmax) const
 Computes the bounding box of the segment.
 
bool intersect (Segment2D< Real > const &S, Real &s, Real &t) const
 Checks for intersection with another segment.
 

Detailed Description

template<typename Real>
class Utils::Segment2D< Real >

A class representing a 2D line segment defined by two endpoints.

The Segment2D class encapsulates a line segment in a two-dimensional space, defined by two points, \( P_a \) and \( P_b \). It provides methods for setting the endpoints, projecting points onto the segment, evaluating points on the segment, and checking for intersections with other segments.

Template Parameters
RealThe data type used for the coordinates of the segment's endpoints, typically a floating-point type (e.g., float, double).

Features

  • Construction: Supports various constructors for initializing the segment.
  • Setup: Methods to set or update the endpoints of the segment.
  • Projection: Projects a point onto the segment and returns the corresponding scalar parameter.
  • Evaluation: Computes points on the segment based on parameter values.
  • Bounding Box: Computes the bounding box of the segment.
  • Intersection: Checks for intersection with another segment and computes parameters.

Methods

Usage

#include "Point2D.h" // Assuming Point2D is defined elsewhere
// Create two points for the segment
A.to_eigen() << 1.0, 2.0; // Set coordinates for point A
B.to_eigen() << 3.0, 4.0; // Set coordinates for point B
// Create a Segment2D object
Segment2D<double> segment(A, B);
// Access endpoints
Point2D<double> start = segment.Pa(); // Get endpoint A
Point2D<double> end = segment.Pb(); // Get endpoint B
// Project a point onto the segment
P.to_eigen() << 2.0, 3.0;
Real param;
segment.projection(P, param); // Project P onto the segment
// Evaluate a point on the segment at parameter s
Real s = 0.5;
Point2D<double> eval_point = segment.eval(s); // Evaluate the midpoint of the segment
A class representing a 2D point in space.
Definition Utils_GG2D.hh:98
P2D const & to_eigen() const
Definition Utils_GG2D.hh:106
Segment2D()=default
Default constructor for the segment.

Constructor & Destructor Documentation

◆ Segment2D() [1/3]

template<typename Real>
Utils::Segment2D< Real >::Segment2D ( )
default

Default constructor for the segment.

Initializes an empty segment with uninitialized endpoints.

◆ Segment2D() [2/3]

template<typename Real>
Utils::Segment2D< Real >::Segment2D ( Segment2D< Real > const & S)
inline

Copy constructor for the segment.

Parameters
SThe segment to copy from.

◆ Segment2D() [3/3]

template<typename Real>
Utils::Segment2D< Real >::Segment2D ( Point2D< Real > const & A,
Point2D< Real > const & B )
inline

Constructor to create a segment from two points.

Parameters
AThe first endpoint of the segment.
BThe second endpoint of the segment.

Member Function Documentation

◆ bbox()

template<typename Real>
void Utils::Segment2D< Real >::bbox ( Point2D< Real > & pmin,
Point2D< Real > & pmax ) const

Computes the bounding box of the segment.

Parameters
pminThe minimum point of the bounding box.
pmaxThe maximum point of the bounding box.

◆ eval() [1/2]

template<typename Real>
Point2D< Real > Utils::Segment2D< Real >::eval ( Real & s) const

Evaluates the segment at a given parameter s.

Parameters
sThe parameter to evaluate on the segment.
Returns
The point on the segment corresponding to the parameter s.

◆ eval() [2/2]

template<typename Real>
Point2D< Real > Utils::Segment2D< Real >::eval ( Real & s,
Real & t ) const

Evaluates the segment based on two parameters s and t.

Parameters
sThe first parameter to evaluate.
tThe second parameter to evaluate.
Returns
The point on the segment corresponding to the parameters s and t.

◆ intersect()

template<typename Real>
bool Utils::Segment2D< Real >::intersect ( Segment2D< Real > const & S,
Real & s,
Real & t ) const

Checks for intersection with another segment.

Parameters
SThe other segment to check for intersection.
sThe parameter along the current segment at the intersection point.
tThe parameter along the other segment at the intersection point.
Returns
true if the segments intersect, false otherwise.

◆ Pa()

template<typename Real>
Point2D< Real > const & Utils::Segment2D< Real >::Pa ( ) const
inline

Returns the first endpoint of the segment.

Returns
The first endpoint \( P_a \).

◆ Pb()

template<typename Real>
Point2D< Real > const & Utils::Segment2D< Real >::Pb ( ) const
inline

Returns the second endpoint of the segment.

Returns
The second endpoint \( P_b \).

◆ projection() [1/2]

template<typename Real>
bool Utils::Segment2D< Real >::projection ( Point2D< Real > const & P,
Real & s ) const

Projects a point onto the segment.

Parameters
PThe point to be projected onto the segment.
sThe parameter along the segment where the projection occurs.
Returns
true if the projection is successful, false otherwise.

◆ projection() [2/2]

template<typename Real>
Point2D< Real > Utils::Segment2D< Real >::projection ( Point2D< Real > const & P,
Real & s,
Real & t ) const

Projects a point onto the segment and returns the projected point.

Parameters
PThe point to be projected onto the segment.
sThe parameter along the segment where the projection occurs.
tThe parameter along the other segment (if applicable).
Returns
The projected point on the segment.

◆ setup() [1/2]

template<typename Real>
void Utils::Segment2D< Real >::setup ( Point2D< Real > const & A,
Point2D< Real > const & B )
inline

Setup the endpoints of the segment using Point2D objects.

Parameters
AThe first endpoint of the segment.
BThe second endpoint of the segment.

◆ setup() [2/2]

template<typename Real>
void Utils::Segment2D< Real >::setup ( Real const A[],
Real const B[] )
inline

Setup the endpoints of the segment using arrays.

Parameters
AArray containing the coordinates of the first endpoint.
BArray containing the coordinates of the second endpoint.

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