mt
 All Classes Files Functions Enumerations Groups Pages
Classes | Public Member Functions | List of all members
mt::Line3 Class Reference

Three-dimensional line class. More...

#include <line3.h>

Classes

class  BadLine
 Ill-defined line exception. More...

Public Member Functions

 Line3 ()
 Line3 (const Unit3 &dir, const Point3 &sup, const DirectionType &type=DIRECTED)
 Constructor for unit direction vector and support point input.
 Line3 (const Vector3 &dir, const Point3 &sup, const DirectionType &type=DIRECTED)
 Constructor for non-unit direction vector and support point input.
 Line3 (const Point3 &sup1, const Point3 &sup2, const DirectionType &type=DIRECTED)
 Constructor for two support point input.
bool operator== (const Line3 &L) const
bool operator!= (const Line3 &L) const
Point3 project (const Point3 &p) const
 Projects point p on current line.
Scalar distance (const Point3 &p) const
 Distance from point p to current line.
Unit3 getDirection () const
 Gets line direction unit vector.
Unit3getDirectionRef ()
const Unit3getDirectionRef () const
Point3 getSupport () const
Point3getSupportRef ()
const Point3getSupportRef () const
DirectionType getDirectionType () const
 Gets line direction type.
DirectionType & getDirectionTypeRef ()
const DirectionType & getDirectionTypeRef () const
Point3 getPoint (const Scalar &t) const
Scalar getParameter (const Point3 &p) const
 Gets line parameter associated to a cartesian point.
void setDirection (const Unit3 &dir)
 Sets line direction unit vector.
void setSupport (const Point3 &sup)
 Sets line support point.
void setDirectionType (const DirectionType &type)
 Sets line direction type.
void setValue (const Unit3 &dir, const Point3 &sup, const DirectionType &type=DIRECTED)
 Sets line with direction vector, support point, and direction type.

Detailed Description

Three-dimensional line class.

Lines are represented using the parametric line equation

\[ \mathbf{x} = \mathbf{p} + \hat{\mathbf{d}}t \]

where

A given line can be represented in infinitely different ways depending on the selected support point. Since the interest is to have a unique line representation regardless of the parameters it was constructed with, a normalized representation of the parametric line equation is used, in which the support point is the line point closest to the current coordinate system. Keep this in mind because when querying for the line support point you will be getting the normalized point instead of the value supplied in the constructor (unless they coincide).

Additionally, a line can be considered to be directed or undirected. If two directed lines differ only in that their direction vectors are antiparallel, they are considered different. If at least one of the lines is undirected, then they are considered to be equal. If left unspecified in the constructor, all lines are considered directed.

After a line is constructed, it is tested to ensure it was well defined. For example, after constructing a line with a direction vector and support point inputs, the support point is tested to ensure it is contained in the line. Another case that can yield an ill-defined situation is a line constructed with two almost-coincident points.

This is an example of how to use the Line3 class:

using namespace mt;
// Some necessary geometric elements
Unit3 dir(1.0, 0.0, 0.0);
Point3 p1(0.0, 2.0, 0.0);
Point3 p2(1.0, 2.0, 0.0);
// Line constructors
Line3 L1;
Line3 L2( dir, p1);
Line3 L3( dir, p2);
Line3 L4( p1, p2, Line3::DIRECTED);
Line3 L5 = -L2;
Line3 L6(-dir, p2, Line3::UNDIRECTED);
// Lines L2, L3, and L4 are exactly the same, although they were constructed
// with different input values. For example, cout << L2 will produce:
// direction: [1 0 0] support: [0 2 0] (directed)
bool test;
test = (L2 == L3); // test = true
test = (L3 == L4); // test = true
// Line L5 differs from lines L2-L4 in that its direction vector is inverted.
// Since these lines are directed, they are not considered equal.
test = (L2 == L5); // test = false
test = (L4 == L5); // test = false
// Like L5, line L6 has an inverted direction vector but it is also
// undirected, so equality tests with the above lines will return true.
// cout << L6 will produce:
// direction: [-1 0 0] support: [0 2 0] (undirected)
test = (L2 == L6); // test = true
test = (L5 == L6); // test = true

Constructor & Destructor Documentation

mt::Line3::Line3 ( )
inline

Default constructor. Creates a directed line coincident with the z axis.

Member Function Documentation

Point3 mt::Line3::getPoint ( const Scalar &  t) const
inline

Gets the cartesian point associated to the line parameter t according to $ \mathbf{x} = \mathbf{p} + \hat{\mathbf{d}}t $.

Point3 mt::Line3::getSupport ( ) const
inline

Gets normalized line support point. Refer to the class description for the meaning of normalized.


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