Core 1.0
Line Class Reference

A line defined by two points. More...

#include <segment.h>

Inheritance diagram for Line:
Segment

Public Member Functions

 Line ()
 Empty.
 Line (const Vector &, const Vector &)
 Creates a line.
Vector Vertex (int) const
 Return one of the vertices of the line.
Vector & Vertex (int)
 Return one of the vertices of the line.
double R (const Vector &) const
 Compute the squared distance between a point and the line.
double R (const Line &) const
 Compute the squared distance between two lines.

Additional Inherited Members

Protected Member Functions inherited from Segment
 Segment ()
 Empty.
 Segment (const Vector &, const Vector &)
 Creates a segment given its end vertices.
 Segment (const Segment2 &, const double &, const double &)
 Create a segment from a segment in the plane.
 ~Segment ()
 Empty.
void Rotate (const Matrix &)
 Rotates a segment.
void Translate (const Vector &)
 Translates a segment.
void Scale (const double &)
 Uniformly scales a segment.
Segment Translated (const Vector &) const
 Translates a segment.
Segment Scaled (const Vector &) const
 Scales a segment.
Segment Scaled (const double &) const
 Uniformly scales a segment.
Segment Rotated (const Matrix &) const
 Rotates a segment.
Segment InverseTransformed (const Frame &) const
 Inverse transformation.
Quadric Equation (const Ray &) const
 Computes the polynomial equation of the Euclidean distance between a ray and the line corresponding to the segment.
Vector Vertex (int) const
 Return one of the end vertex of the axis.
Vector & Vertex (int)
 Return one of the end vertex of the axis.
Vector VertexAt (const double &) const
 Compute a point on the segment.
Vector Center () const
 Compute the center of the segment.
bool Intersect (const Box &) const
 Check if a segment intersects a box.
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.
double R (const Vector &, double &) const
 Compute the squared distance to the segment.
double R (const Segment &) const
 Compute the squared distance between two segments.
Vector Normal (const Vector &) const
 Compute the normal vector between a point and its projection onto the segment.
bool Equal (const Segment &, const double &) const
 Test if two segments are almost equal.
Static Protected Member Functions inherited from Segment
static Quadric EdgeEquation (const Ray &, const Vector &, const Vector &, const Vector &)
 Compute the polynomial equation of the distance function along the ray.
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.
Protected Attributes inherited from Segment
Vector b = Vector::Z
 End vertices of the segment.

Detailed Description

A line defined by two points.

The line goes through the points Line::a and Line::b, its direction is the (not normalized) vector \( b-a \). The two points should be distinct.

Constructor & Destructor Documentation

◆ Line()

Line::Line ( const Vector & a,
const Vector & b )
inlineexplicit

Creates a line.

Parameters
a,bTwo points on the line.

Member Function Documentation

◆ R() [1/2]

double Line::R ( const Line & line) const

Compute the squared distance between two lines.

Let \( u=b-a \) and \( v \) be the direction vectors of the two lines. The closest points are found by solving a 2x2 linear system whose determinant is \( e=\|u\|^2\|v\|^2-(u\cdot v)^2=\|u\|^2\|v\|^2\sin^2\theta \), where \( \theta \) is the angle between the lines.

The lines are considered parallel when \( \sin^2\theta<10^{-12} \), i.e. \( \theta<10^{-6} \). This test is relative to the lengths of the direction vectors, so that it does not depend on the scale of the points defining the lines. In that case the system is ill-conditioned, and the result is the squared distance between the first point of this line and the other line. It is exact for parallel lines, and differs from the squared distance between two almost parallel lines only by a term of the order of \( \theta \) times the offset of the closest points along the lines.

Parameters
lineLine.
Returns
The squared Euclidean distance, which is positive or null (null if the lines intersect or are identical).
See also
Line::R(const Vector&) const

◆ R() [2/2]

double Line::R ( const Vector & p) const

Compute the squared distance between a point and the line.

The direction vector is not normalized, the squared distance is computed as \( \|p-a\|^2 - \frac{((p-a)\cdot(b-a))^2}{\|b-a\|^2} \).

Parameters
pPoint.
Returns
The squared Euclidean distance, which is positive or null.
See also
Line::R(const Line&) const