CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
Public Types | Public Member Functions | Public Attributes
claw::math::line_2d< T > Class Template Reference

A straight line in a two dimensional space. More...

#include <line_2d.hpp>

List of all members.

Public Types

typedef T value_type
 The type of the values we store.
typedef line_2d< value_typeself_type
 The type of the current class.
typedef coordinate_2d< value_typepoint_type
 The type of the reference point.
typedef vector_2d< value_typedirection_type
 The type of the direction vector.

Public Member Functions

 line_2d ()
 Constructor.
template<class U >
 line_2d (const line_2d< U > &that)
 Constructor.
 line_2d (const point_type &_origin, const direction_type &_direction)
 Constructor with initializations.
 line_2d (const value_type &ox, const value_type &oy, const value_type &dx, const value_type &dy)
 Constructor with initializations.
bool parallel (const self_type &that) const
 Tell if two lines are parallels.
bool orthogonal (const self_type &that) const
 Tell if two lines are orthogonal.
point_type intersection (const self_type &that) const
 Get the point at the intersection of two lines.
value_type y_value (const value_type &x) const
 Get the y value of the point of the line at position x.

Public Attributes

point_type origin
 A reference point on the line.
direction_type direction
 Direction.

Detailed Description

template<class T>
class claw::math::line_2d< T >

A straight line in a two dimensional space.

Author:
Julien Jorge

Definition at line 45 of file line_2d.hpp.


Member Typedef Documentation

template<class T>
typedef vector_2d<value_type> claw::math::line_2d< T >::direction_type

The type of the direction vector.

Definition at line 58 of file line_2d.hpp.

template<class T>
typedef coordinate_2d<value_type> claw::math::line_2d< T >::point_type

The type of the reference point.

Definition at line 55 of file line_2d.hpp.

template<class T>
typedef line_2d<value_type> claw::math::line_2d< T >::self_type

The type of the current class.

Definition at line 52 of file line_2d.hpp.

template<class T>
typedef T claw::math::line_2d< T >::value_type

The type of the values we store.

Definition at line 49 of file line_2d.hpp.


Constructor & Destructor Documentation

template<class T >
claw::math::line_2d< T >::line_2d ( )

Constructor.

Definition at line 36 of file line_2d.tpp.

{

} // line_2d::line_2d() [constructor]
template<class T >
template<class U >
claw::math::line_2d< T >::line_2d ( const line_2d< U > &  that)

Constructor.

Parameters:
thatLine to copy from.

Definition at line 48 of file line_2d.tpp.

  : origin(that.origin), direction(that.direction)
{

} // line_2d::line_2d() [copy constructor]
template<class T >
claw::math::line_2d< T >::line_2d ( const point_type _origin,
const direction_type _direction 
)

Constructor with initializations.

Parameters:
_originA point on the line.
_directionThe direction of the line.

Definition at line 62 of file line_2d.tpp.

  : origin(_origin), direction(_direction)
{

} // line_2d::line_2d() [constructor with values]
template<class T >
claw::math::line_2d< T >::line_2d ( const value_type ox,
const value_type oy,
const value_type dx,
const value_type dy 
)

Constructor with initializations.

Parameters:
oxX-coordinate of the origin.
oyY-coordinate of the origin.
dxX direction of the line.
dyY direction of the line.

Definition at line 77 of file line_2d.tpp.

  : origin(ox, oy), direction(dx, dy)
{

} // line_2d::line_2d() [constructor with detailed origin & direction]

Member Function Documentation

template<class T >
claw::math::line_2d< T >::point_type claw::math::line_2d< T >::intersection ( const self_type that) const

Get the point at the intersection of two lines.

Parameters:
thatThe other line.
Remarks:
The result if unknow if the two lines are parallel.

Definition at line 115 of file line_2d.tpp.

References claw::math::line_2d< T >::direction, claw::math::line_2d< T >::origin, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  point_type result;

  if ( ! parallel( that ) )
    {
      point_type delta( that.origin - origin );
      value_type n, m;
      
      n = direction.x * delta.y - direction.y * delta.x;
      m = that.direction.x * direction.y - direction.x * that.direction.y;

      result.x = that.origin.x + (n * that.direction.x) / m;
      result.y = that.origin.y + (n * that.direction.y) / m;
    }

  return result;
} // line_2d::intersection()
template<class T >
bool claw::math::line_2d< T >::orthogonal ( const self_type that) const

Tell if two lines are orthogonal.

Parameters:
thatThe other line.

Definition at line 102 of file line_2d.tpp.

References claw::math::line_2d< T >::direction.

{
  return !( direction.dot_product( that.direction ) );
} // line_2d::orthogonal()
template<class T >
bool claw::math::line_2d< T >::parallel ( const self_type that) const

Tell if two lines are parallels.

Parameters:
thatThe other line.

Definition at line 90 of file line_2d.tpp.

References claw::math::line_2d< T >::direction, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

{
  return !( (direction.x * that.direction.y)
            - (that.direction.x * direction.y) );
} // line_2d::parallel()
template<class T >
claw::math::line_2d< T >::value_type claw::math::line_2d< T >::y_value ( const value_type x) const

Get the y value of the point of the line at position x.

Parameters:
xThe X-coordinate for which we want the Y-coordinate.

Definition at line 141 of file line_2d.tpp.

{
  return (direction.y * (x - origin.x) + direction.x * origin.y) / direction.x;
} // line_2d::y_value()

Member Data Documentation

template<class T>
direction_type claw::math::line_2d< T >::direction
template<class T>
point_type claw::math::line_2d< T >::origin

A reference point on the line.

Definition at line 75 of file line_2d.hpp.

Referenced by claw::math::line_2d< T >::intersection().


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