Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
Segment2 Class Reference

Segments in the plane. More...

#include <segment.h>

Inheritance diagram for Segment2:
Line2

Public Member Functions

 Segment2 ()
 Empty.
 
 Segment2 (const Vector2 &, const Vector2 &)
 Creates a planar segment given end vertices. More...
 
 Segment2 (const Segment &)
 Creates a planar segment given a three dimensional segment. More...
 
 ~Segment2 ()
 Empty.
 
Vector2 Vertex (int) const
 Return one of the end vertex of the axis.
 
Vector2Vertex (int)
 Return one of the end vertex of the axis.
 
Vector2 VertexAt (const double &) const
 Compute a point on the segment. More...
 
Vector2 Center () const
 Compute the center of the segment.
 
Vector2 GetAxis () const
 Returns the normalized axis vector.
 
Box2 GetBox () const
 Compute the bounding box of the segment.
 
Vector2 Orthogonal () const
 Compute an orthogonal vector to the segment. More...
 
void Translate (const Vector2 &)
 Translates a segment. More...
 
void Rotate (const Matrix2 &)
 Translates a segment. More...
 
void Scale (const double &)
 Uniformly scales a segment. More...
 
double Length () const
 Return axis length.
 
void Draw (QGraphicsScene &, const QPen &=QPen()) const
 Draw a segment. More...
 
void DrawArrow (QGraphicsScene &, const double &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw a segment as an arrow. More...
 
double R (const Vector2 &) const
 Compute the squared distance to the segment. More...
 
double R (const Vector2 &, double &) const
 Compute the squared distance to the axis edge characterized by its end points. More...
 
Vector2 Normal (const Vector2 &) const
 Compute the normal vector between a point and its projection onto the segment. More...
 
bool Intersect (const Segment2 &) const
 Test if two segments intersect. More...
 
bool IntersectOpen (const Segment2 &) const
 This functions tests if two segments intersect. More...
 
bool Intersection (const Segment2 &, Vector2 &) const
 Compute the intersection between two segments. More...
 

Static Public Member Functions

static Vector2 Intersect (const Vector2 &, const Vector2 &, const double, const double, const double=0.0)
 Compute the intersection between the line f(x)=y and a line such that f(a)=va and f(b)=vb, on the segment ab. More...
 

Static Public Attributes

static constexpr const double epsilon = 1e-8
 Epsilon value for intersection test.
 

Protected Attributes

Vector2 b = Vector2::X
 End vertices of the segment.
 

Friends

std::ostream & operator<< (std::ostream &, const Segment2 &)
 Overloaded. More...
 
bool operator== (const Segment2 &, const Segment2 &)
 Compare two segments. More...
 

Detailed Description

Segments in the plane.

A segment stores its end vertices.

Constructor & Destructor Documentation

◆ Segment2() [1/2]

Segment2::Segment2 ( const Vector2 a,
const Vector2 b 
)
inlineexplicit

Creates a planar segment given end vertices.

Parameters
a,bEnd vertices of the segment.

◆ Segment2() [2/2]

Segment2::Segment2 ( const Segment s)
inlineexplicit

Creates a planar segment given a three dimensional segment.

Parameters
sSegment.

Member Function Documentation

◆ Draw()

void Segment2::Draw ( QGraphicsScene &  scene,
const QPen &  pen = QPen() 
) const

Draw a segment.

Parameters
sceneGraphics scene.
penThe pen.

◆ DrawArrow()

void Segment2::DrawArrow ( QGraphicsScene &  scene,
const double &  s,
const QPen &  pen = QPen(),
const QBrush &  brush = QBrush() 
) const

Draw a segment as an arrow.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush.
sSize of the arrow head.

◆ Intersect() [1/2]

bool Segment2::Intersect ( const Segment2 segment) const

Test if two segments intersect.

This function computes the intersection and test the intersection parameters. Two segments that share an end point are detected as intersecting.

Parameters
segmentOther segment.

◆ Intersect() [2/2]

Vector2 Segment2::Intersect ( const Vector2 a,
const Vector2 b,
const double  va,
const double  vb,
const double  y = 0.0 
)
static

Compute the intersection between the line f(x)=y and a line such that f(a)=va and f(b)=vb, on the segment ab.

Parameters
a,bPoints.
va,vbValues.
yThreshold.

◆ Intersection()

bool Segment2::Intersection ( const Segment2 e,
Vector2 p 
) const

Compute the intersection between two segments.

Parameters
eOther segment.
pIntersection point.

◆ IntersectOpen()

bool Segment2::IntersectOpen ( const Segment2 segment) const

This functions tests if two segments intersect.

The algorithm avoids the computation of the intersection. Instead, it checks whether the two points of one segment lie on the same half space defined by the line of the other segment.

Contrary to bool Intersect(const Segment2&), two segments that share one point are not detected as intersecting.

Parameters
segmentOther segment.

◆ Normal()

Vector2 Segment2::Normal ( const Vector2 p) const

Compute the normal vector between a point and its projection onto the segment.

Parameters
pPoint.

◆ Orthogonal()

Vector2 Segment2::Orthogonal ( ) const

Compute an orthogonal vector to the segment.

The returned vector is not normalized.

◆ R() [1/2]

double Segment2::R ( const Vector2 p) const

Compute the squared distance to the segment.

Parameters
pPoint.

◆ R() [2/2]

double Segment2::R ( const Vector2 p,
double &  s 
) const

Compute the squared distance to the axis edge characterized by its end points.

Parameters
pPoint.
sLinear coefficient corresponding to the projection of argument point p onto the edge.

◆ Rotate()

void Segment2::Rotate ( const Matrix2 r)

Translates a segment.

Parameters
rRotation matrix.

◆ Scale()

void Segment2::Scale ( const double &  s)

Uniformly scales a segment.

Parameters
sScaling factor.

◆ Translate()

void Segment2::Translate ( const Vector2 t)

Translates a segment.

Parameters
tTranslation vector.

◆ VertexAt()

Vector2 Segment2::VertexAt ( const double &  t) const
inline

Compute a point on the segment.

Parameters
tInterpolation parameter.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Segment2 segment 
)
friend

Overloaded.

Parameters
sStream.
segmentThe segment.

◆ operator==

bool operator== ( const Segment2 a,
const Segment2 b 
)
friend

Compare two segments.

Parameters
a,bSegments.