TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Line Class Reference

#include <Line.h>

Public Member Functions

 Line ()
 
 Line (class BinaryInput &b)
 
void serialize (class BinaryOutput &b) const
 
void deserialize (class BinaryInput &b)
 
virtual ~Line ()
 
Vector3 closestPoint (const Vector3 &pt) const
 
double distance (const Vector3 &point) const
 
Vector3 point () const
 
Vector3 direction () const
 
Vector3 intersection (const Plane &plane) const
 
Vector3 closestPoint (const Line &B, float &minDist) const
 
Vector3 closestPoint (const Line &B) const
 

Static Public Member Functions

static Line fromTwoPoints (const Vector3 &point1, const Vector3 &point2)
 
static Line fromPointAndDirection (const Vector3 &point, const Vector3 &direction)
 

Protected Member Functions

 Line (const Vector3 &point, const Vector3 &direction)
 

Protected Attributes

Vector3 _point
 
Vector3 _direction
 

Detailed Description

An infinite 3D line.

Constructor & Destructor Documentation

G3D::Line::Line ( const Vector3 point,
const Vector3 direction 
)
inlineprotected
31  {
32  _point = point;
34  }
Vector3 direction() const
Definition: Line.cpp:63
Vector3 direction() const
Definition: Vector3.h:756
Vector3 _direction
Definition: Line.h:29
Vector3 _point
Definition: Line.h:28
Vector3 point() const
Definition: Line.cpp:58

+ Here is the call graph for this function:

G3D::Line::Line ( )
inline

Undefined (provided for creating Array<Line> only)

39 {}

+ Here is the caller graph for this function:

G3D::Line::Line ( class BinaryInput b)
35  {
36  deserialize(b);
37 }
void deserialize(class BinaryInput &b)
Definition: Line.cpp:46

+ Here is the call graph for this function:

virtual G3D::Line::~Line ( )
inlinevirtual
47 {}

Member Function Documentation

Vector3 G3D::Line::closestPoint ( const Vector3 pt) const

Returns the closest point on the line to point.

52  {
53  float t = _direction.dot(pt - _point);
54  return _point + _direction * t;
55 }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
Vector3 _direction
Definition: Line.h:29
Vector3 _point
Definition: Line.h:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 G3D::Line::closestPoint ( const Line B,
float &  minDist 
) const

Finds the closest point to the two lines.

Parameters
minDistReturns the minimum distance between the lines.

[http://objectmix.com/graphics/133793-coordinates-closest-points-pair-skew-lines.html]

68  {
69  const Vector3& P1 = _point;
70  const Vector3& U1 = _direction;
71 
72  Vector3 P2 = B.point();
73  Vector3 U2 = B.direction();
74 
75  const Vector3& P21 = P2 - P1;
76  const Vector3& M = U2.cross(U1);
77  float m2 = M.length();
78 
79  Vector3 R = P21.cross(M) / m2;
80 
81  float t1 = R.dot(U2);
82 
83  minDist = (float)abs(P21.dot(M)) / sqrt(m2);
84 
85  return P1 + t1 * U1;
86 }
double abs(double fValue)
Definition: g3dmath.h:617
Vector3 direction() const
Definition: Vector3.h:756
float length() const
Definition: Vector3.h:751
Vector3 _direction
Definition: Line.h:29
Vector3 _point
Definition: Line.h:28
Vector3 __fastcall cross(const Vector3 &rkVector) const
Definition: Vector3.h:776

+ Here is the call graph for this function:

Vector3 G3D::Line::closestPoint ( const Line B) const
inline
96  {
97  float m;
98  return closestPoint(B, m);
99  }
Vector3 closestPoint(const Vector3 &pt) const
Definition: Line.cpp:52

+ Here is the call graph for this function:

void G3D::Line::deserialize ( class BinaryInput b)
46  {
49 }
void deserialize(class BinaryInput &b)
Definition: Vector3.cpp:190
Vector3 _direction
Definition: Line.h:29
Vector3 _point
Definition: Line.h:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 G3D::Line::direction ( ) const

Returns the direction (or negative direction) of the line

63  {
64  return _direction;
65 }
Vector3 _direction
Definition: Line.h:29

+ Here is the caller graph for this function:

double G3D::Line::distance ( const Vector3 point) const
inline

Returns the distance between point and the line

71  {
72  return (closestPoint(point) - point).magnitude();
73  }
Vector3 closestPoint(const Vector3 &pt) const
Definition: Line.cpp:52
Vector3 point() const
Definition: Line.cpp:58

+ Here is the call graph for this function:

static Line G3D::Line::fromPointAndDirection ( const Vector3 point,
const Vector3 direction 
)
inlinestatic

Creates a line from a point and a (nonzero) direction.

59  {
60  return Line(point, direction);
61  }
Line()
Definition: Line.h:39
Vector3 direction() const
Definition: Line.cpp:63
Vector3 point() const
Definition: Line.cpp:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Line G3D::Line::fromTwoPoints ( const Vector3 point1,
const Vector3 point2 
)
inlinestatic

Constructs a line from two (not equal) points.

52  {
53  return Line(point1, point2 - point1);
54  }
Line()
Definition: Line.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 G3D::Line::intersection ( const Plane plane) const

Returns the point where the line and plane intersect. If there is no intersection, returns a point at infinity.

17  {
18  float d;
19  Vector3 normal = plane.normal();
20  plane.getEquation(normal, d);
21  float rate = _direction.dot(normal);
22 
23  if (rate == 0) {
24 
25  return Vector3::inf();
26 
27  } else {
28  float t = -(d + _point.dot(normal)) / rate;
29 
30  return _point + _direction * t;
31  }
32 }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
Vector3 _direction
Definition: Line.h:29
Vector3 _point
Definition: Line.h:28
static const Vector3 & inf()
Definition: Vector3.cpp:124

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 G3D::Line::point ( ) const

Returns a point on the line

58  {
59  return _point;
60 }
Vector3 _point
Definition: Line.h:28

+ Here is the caller graph for this function:

void G3D::Line::serialize ( class BinaryOutput b) const
40  {
41  _point.serialize(b);
43 }
void serialize(class BinaryOutput &b) const
Definition: Vector3.cpp:219
Vector3 _direction
Definition: Line.h:29
Vector3 _point
Definition: Line.h:28

+ Here is the call graph for this function:

Member Data Documentation

Vector3 G3D::Line::_direction
protected
Vector3 G3D::Line::_point
protected

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