The Nebula Device 3: Math::line Class Reference

From The Nebula Device 3

Math::line Class Reference

#include <line.h>


Detailed Description

A line in 3d space.

(C) 2004 RadonLabs GmbH

Public Member Functions

 line ()
 default constructor
 line (const point &startPoint, const point &endPoint)
 component constructor
 line (const line &rhs)
 copy constructor
void set (const point &startPoint, const point &endPoint)
 set start and end point
const point & start () const
 get start point
point end () const
 get end point
const vector & vec () const
 get vector
scalar length () const
 get length
scalar lengthsq () const
 get squared length
scalar distance (const point &p) const
 minimal distance of point to line
bool intersect (const line &l, point &pa, point &pb) const
 intersect with line
scalar closestpoint (const point &p) const
 return t of the closest point on the line
point pointat (scalar t) const
 return p = b + m*t

Member Function Documentation

bool Math::line::intersect ( const line &  l,
point &  pa,
point &  pb 
) const

intersect with line

Get line/line intersection. Returns the shortest line between two lines.

Todo:
: Untested! Replace with simpler code.

scalar Math::line::closestpoint ( const point &  p  )  const [inline]

return t of the closest point on the line

Returns a point on the line which is closest to a another point in space. This just returns the parameter t on where the point is located. If t is between 0 and 1, the point is on the line, otherwise not. To get the actual 3d point p:

p = m + b*t

point Math::line::pointat ( scalar  t  )  const [inline]

return p = b + m*t

Returns p = b + m * t, given t. Note that the point is not on the line if 0.0 > t > 1.0