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

A segment defined by its end vertices. More...

#include <segment.h>

Inheritance diagram for Segment:
Line RayStep SmoothSegment

Public Member Functions

 Segment ()
 Empty.
 
 Segment (const Vector &, const Vector &)
 Creates a segment given its end vertices. More...
 
 ~Segment ()
 Empty.
 
void Rotate (const Matrix &)
 Rotates a segment. More...
 
void Translate (const Vector &)
 Translates a segment. More...
 
void Scale (const double &)
 Uniformly scales a segment. More...
 
Segment Translated (const Vector &) const
 Translates a segment. More...
 
Segment Scaled (const Vector &) const
 Scales a segment. More...
 
Segment Scaled (const double &) const
 Uniformly scales a segment. More...
 
Segment Rotated (const Matrix &) const
 Rotates a segment. More...
 
Segment InverseTransformed (const Frame &) const
 Inverse transformation. More...
 
Quadric Equation (const Ray &) const
 Computes the polynomial equation of the Euclidean distance between a ray and the line corresponding to the segment. More...
 
Vector Vertex (int) const
 Return one of the end vertex of the axis.
 
VectorVertex (int)
 Return one of the end vertex of the axis.
 
Vector VertexAt (const double &) const
 Compute a point on the segment. More...
 
Vector Center () const
 Compute the center of the segment.
 
bool Intersect (const Box &) const
 Check if a segment intersects a box. More...
 
Vector GetAxis () const
 Returns the normalized axis vector.
 
Box GetBox () const
 Compute the bounding box of the segment.
 
double Length () const
 Return axis length.
 
double R (const Vector &) const
 Compute the squared distance to the segment. More...
 
double R (const Vector &, double &) const
 Compute the squared distance to the segment. More...
 
double R (const Segment &) const
 Compute the squared distance between two segments. More...
 
Vector Normal (const Vector &) const
 Compute the normal vector between a point and its projection onto the segment. More...
 
bool Equal (const Segment &, const double &) const
 Test if two segments are almost equal. More...
 

Static Public Member Functions

static Quadric EdgeEquation (const Ray &, const Vector &, const Vector &, const Vector &)
 Compute the polynomial equation of the distance function along the ray. More...
 
static Vector Intersect (const Vector &, const Vector &, const double, const double, 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...
 

Protected Attributes

Vector b = Vector::Z
 End vertices of the segment.
 

Friends

std::ostream & operator<< (std::ostream &, const Segment &)
 Overloaded. More...
 

Detailed Description

A segment defined by its end vertices.

Axis inherits Segment and extends the structure by storing the normalized axis vector and its length. Lines are implemented by the class Line.

How do I compute the intersection of two segments?
In general, segments do not intersect, use the distance function.

Segment a(Vector(0,1,-1),Vector(-1,0,3));
Segment b(Vector(0,1,-1),Vector(-1,0,3));
double r=a.R(b);
A segment defined by its end vertices.
Definition: segment.h:17
Vector b
End vertices of the segment.
Definition: segment.h:19
Vectors in three dimensions.
Definition: evector.h:21

Alternatively, it is possible to compute the intersection between two segments in the plane, using Segment2::Intersect(const Segment2&).

Constructor & Destructor Documentation

◆ Segment()

Segment::Segment ( const Vector a,
const Vector b 
)
inlineexplicit

Creates a segment given its end vertices.

Parameters
a,bEnd vertices of the segment.

Member Function Documentation

◆ EdgeEquation()

Quadric Segment::EdgeEquation ( const Ray ray,
const Vector a,
const Vector ,
const Vector axis 
)
static

Compute the polynomial equation of the distance function along the ray.

Parameters
rayThe ray.
aFirst vertex of the segment.
axisAxis.

◆ Equal()

bool Segment::Equal ( const Segment s,
const double &  epsilon 
) const

Test if two segments are almost equal.

This function computes the distance between the end vertices of the two argument segments. If the norm infinity of this difference is greater than the epsilon threshold value, then the segments are different.

Parameters
sOther segment.
epsilonPrecision. This is a convenience function which is the same as:
Segment a,b; // Two segments
double e; // Epsilon value
bool t=Vector::Equal(a.Vertex(0), b.Vertex(0), e) && Vector::Equal(a.Vertex(1), b.Vertex(1), e);
Vector Vertex(int) const
Return one of the end vertex of the axis.
Definition: segment.h:76
static bool Equal(const Vector &, const Vector &, const double &=0.0001)
Test if two vectors are almost equal.
Definition: evector.cpp:85

◆ Equation()

Quadric Segment::Equation ( const Ray ray) const

Computes the polynomial equation of the Euclidean distance between a ray and the line corresponding to the segment.

Parameters
rayThe ray.

◆ Intersect() [1/2]

bool Segment::Intersect ( const Box box) const

Check if a segment intersects a box.

Parameters
boxThe box.

◆ Intersect() [2/2]

Vector Segment::Intersect ( const Vector a,
const Vector b,
const double  va,
const double  vb,
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.

◆ InverseTransformed()

Segment Segment::InverseTransformed ( const Frame f) const

Inverse transformation.

Parameters
fThe frame.

◆ Normal()

Vector Segment::Normal ( const Vector p) const

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

Parameters
pPoint.

◆ R() [1/3]

double Segment::R ( const Segment segment) const

Compute the squared distance between two segments.

Parameters
segmentThe segment.

◆ R() [2/3]

double Segment::R ( const Vector p) const

Compute the squared distance to the segment.

Parameters
pPoint.

◆ R() [3/3]

double Segment::R ( const Vector p,
double &  s 
) const

Compute the squared distance to the segment.

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

◆ Rotate()

void Segment::Rotate ( const Matrix r)

Rotates a segment.

Only the vertices and the axis are modified, the length is preserved.

Parameters
rRotation matrix.

◆ Rotated()

Segment Segment::Rotated ( const Matrix r) const

Rotates a segment.

Parameters
rRotation matrix.

◆ Scale()

void Segment::Scale ( const double &  s)

Uniformly scales a segment.

Parameters
sScaling factor.

◆ Scaled() [1/2]

Segment Segment::Scaled ( const double &  s) const

Uniformly scales a segment.

Parameters
sScaling factor.

◆ Scaled() [2/2]

Segment Segment::Scaled ( const Vector s) const

Scales a segment.

Parameters
sScaling vector.

◆ Translate()

void Segment::Translate ( const Vector t)

Translates a segment.

Parameters
tTranslation vector.

◆ Translated()

Segment Segment::Translated ( const Vector t) const

Translates a segment.

Parameters
tTranslation vector.

◆ VertexAt()

Vector Segment::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 Segment segment 
)
friend

Overloaded.

Parameters
sStream.
segmentThe segment.