arsa  2.7
Public Member Functions | Public Attributes | List of all members
irr::core::line3d< T > Class Template Reference

3D line between two points with intersection methods. More...

#include <line3d.h>

Public Member Functions

 line3d ()
 Default constructor. More...
 
 line3d (T xa, T ya, T za, T xb, T yb, T zb)
 Constructor with two points. More...
 
 line3d (const vector3d< T > &start, const vector3d< T > &end)
 Constructor with two points as vectors. More...
 
line3d< T > operator+ (const vector3d< T > &point) const
 
line3d< T > & operator+= (const vector3d< T > &point)
 
line3d< T > operator- (const vector3d< T > &point) const
 
line3d< T > & operator-= (const vector3d< T > &point)
 
bool operator== (const line3d< T > &other) const
 
bool operator!= (const line3d< T > &other) const
 
void setLine (const T &xa, const T &ya, const T &za, const T &xb, const T &yb, const T &zb)
 Set this line to a new line going through the two points. More...
 
void setLine (const vector3d< T > &nstart, const vector3d< T > &nend)
 Set this line to a new line going through the two points. More...
 
void setLine (const line3d< T > &line)
 Set this line to new line given as parameter. More...
 
getLength () const
 Get length of line. More...
 
getLengthSQ () const
 Get squared length of line. More...
 
vector3d< T > getMiddle () const
 Get middle of line. More...
 
vector3d< T > getVector () const
 Get vector of line. More...
 
bool isPointBetweenStartAndEnd (const vector3d< T > &point) const
 Check if the given point is between start and end of the line. More...
 
vector3d< T > getClosestPoint (const vector3d< T > &point) const
 Get the closest point on this line to a point. More...
 
bool getIntersectionWithSphere (const vector3d< T > &sorigin, T sradius, f64 &outdistance) const
 Check if the line intersects with a sphere. More...
 

Public Attributes

vector3d< T > start
 Start point of line. More...
 
vector3d< T > end
 End point of line. More...
 

Detailed Description

template<class T>
class irr::core::line3d< T >

3D line between two points with intersection methods.

Definition at line 18 of file line3d.h.

Constructor & Destructor Documentation

◆ line3d() [1/3]

template<class T>
irr::core::line3d< T >::line3d ( )
inline

Default constructor.

line from (0,0,0) to (1,1,1)

Definition at line 24 of file line3d.h.

24 : start(0,0,0), end(1,1,1) {}
vector3d< T > end
End point of line.
Definition: line3d.h:132
vector3d< T > start
Start point of line.
Definition: line3d.h:130

◆ line3d() [2/3]

template<class T>
irr::core::line3d< T >::line3d ( xa,
ya,
za,
xb,
yb,
zb 
)
inline

Constructor with two points.

Definition at line 26 of file line3d.h.

26 : start(xa, ya, za), end(xb, yb, zb) {}
vector3d< T > end
End point of line.
Definition: line3d.h:132
vector3d< T > start
Start point of line.
Definition: line3d.h:130

◆ line3d() [3/3]

template<class T>
irr::core::line3d< T >::line3d ( const vector3d< T > &  start,
const vector3d< T > &  end 
)
inline

Constructor with two points as vectors.

Definition at line 28 of file line3d.h.

28 : start(start), end(end) {}
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571
vector3d< T > end
End point of line.
Definition: line3d.h:132
vector3d< T > start
Start point of line.
Definition: line3d.h:130

Member Function Documentation

◆ getClosestPoint()

template<class T>
vector3d<T> irr::core::line3d< T >::getClosestPoint ( const vector3d< T > &  point) const
inline

Get the closest point on this line to a point.

Parameters
pointThe point to compare to.
Returns
The nearest point which is part of the line.

Definition at line 89 of file line3d.h.

90  {
91  vector3d<T> c = point - start;
92  vector3d<T> v = end - start;
93  T d = (T)v.getLength();
94  v /= d;
95  T t = v.dotProduct(c);
96 
97  if (t < (T)0.0)
98  return start;
99  if (t > d)
100  return end;
101 
102  v *= t;
103  return start + v;
104  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571
const GLdouble * v
Definition: SDL_opengl.h:2064
vector3d< T > end
End point of line.
Definition: line3d.h:132
vector3d< T > start
Start point of line.
Definition: line3d.h:130
const GLubyte * c

◆ getIntersectionWithSphere()

template<class T>
bool irr::core::line3d< T >::getIntersectionWithSphere ( const vector3d< T > &  sorigin,
sradius,
f64 outdistance 
) const
inline

Check if the line intersects with a sphere.

Parameters
soriginOrigin of the sphere.
sradiusRadius of the sphere.
outdistanceThe distance to the first intersection point.
Returns
True if there is an intersection. If there is one, the distance to the first intersection point is stored in outdistance.

Definition at line 113 of file line3d.h.

114  {
115  const vector3d<T> q = sorigin - start;
116  T c = q.getLength();
117  T v = q.dotProduct(getVector().normalize());
118  T d = sradius * sradius - (c*c - v*v);
119 
120  if (d < 0.0)
121  return false;
122 
123  outdistance = v - core::squareroot ( d );
124  return true;
125  }
GLdouble GLdouble GLdouble GLdouble q
Definition: SDL_opengl.h:2087
REALINLINE f32 squareroot(const f32 f)
Definition: irrMath.h:495
vector3d< T > getVector() const
Get vector of line.
Definition: line3d.h:71
const GLdouble * v
Definition: SDL_opengl.h:2064
vector3d< T > start
Start point of line.
Definition: line3d.h:130
const GLubyte * c

◆ getLength()

template<class T>
T irr::core::line3d< T >::getLength ( ) const
inline

Get length of line.

Returns
Length of line.

Definition at line 56 of file line3d.h.

56 { return start.getDistanceFrom(end); }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ getLengthSQ()

template<class T>
T irr::core::line3d< T >::getLengthSQ ( ) const
inline

Get squared length of line.

Returns
Squared length of line.

Definition at line 60 of file line3d.h.

60 { return start.getDistanceFromSQ(end); }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ getMiddle()

template<class T>
vector3d<T> irr::core::line3d< T >::getMiddle ( ) const
inline

Get middle of line.

Returns
Center of line.

Definition at line 64 of file line3d.h.

65  {
66  return (start + end)/(T)2;
67  }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ getVector()

template<class T>
vector3d<T> irr::core::line3d< T >::getVector ( ) const
inline

Get vector of line.

Returns
vector of line.

Definition at line 71 of file line3d.h.

72  {
73  return end - start;
74  }
GLuint GLuint end
Definition: SDL_opengl.h:1571
vector3d< T > start
Start point of line.
Definition: line3d.h:130

◆ isPointBetweenStartAndEnd()

template<class T>
bool irr::core::line3d< T >::isPointBetweenStartAndEnd ( const vector3d< T > &  point) const
inline

Check if the given point is between start and end of the line.

Assumes that the point is already somewhere on the line.

Parameters
pointThe point to test.
Returns
True if point is on the line between start and end, else false.

Definition at line 81 of file line3d.h.

82  {
83  return point.isBetweenPoints(start, end);
84  }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ operator!=()

template<class T>
bool irr::core::line3d< T >::operator!= ( const line3d< T > &  other) const
inline

Definition at line 40 of file line3d.h.

41  { return !(start==other.start && end==other.end) || (end==other.start && start==other.end);}
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ operator+()

template<class T>
line3d<T> irr::core::line3d< T >::operator+ ( const vector3d< T > &  point) const
inline

Definition at line 32 of file line3d.h.

32 { return line3d<T>(start + point, end + point); }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ operator+=()

template<class T>
line3d<T>& irr::core::line3d< T >::operator+= ( const vector3d< T > &  point)
inline

Definition at line 33 of file line3d.h.

33 { start += point; end += point; return *this; }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ operator-()

template<class T>
line3d<T> irr::core::line3d< T >::operator- ( const vector3d< T > &  point) const
inline

Definition at line 35 of file line3d.h.

35 { return line3d<T>(start - point, end - point); }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ operator-=()

template<class T>
line3d<T>& irr::core::line3d< T >::operator-= ( const vector3d< T > &  point)
inline

Definition at line 36 of file line3d.h.

36 { start -= point; end -= point; return *this; }
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ operator==()

template<class T>
bool irr::core::line3d< T >::operator== ( const line3d< T > &  other) const
inline

Definition at line 38 of file line3d.h.

39  { return (start==other.start && end==other.end) || (end==other.start && start==other.end);}
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ setLine() [1/3]

template<class T>
void irr::core::line3d< T >::setLine ( const T &  xa,
const T &  ya,
const T &  za,
const T &  xb,
const T &  yb,
const T &  zb 
)
inline

Set this line to a new line going through the two points.

Definition at line 45 of file line3d.h.

46  {start.set(xa, ya, za); end.set(xb, yb, zb);}
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ setLine() [2/3]

template<class T>
void irr::core::line3d< T >::setLine ( const vector3d< T > &  nstart,
const vector3d< T > &  nend 
)
inline

Set this line to a new line going through the two points.

Definition at line 48 of file line3d.h.

49  {start.set(nstart); end.set(nend);}
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

◆ setLine() [3/3]

template<class T>
void irr::core::line3d< T >::setLine ( const line3d< T > &  line)
inline

Set this line to new line given as parameter.

Definition at line 51 of file line3d.h.

52  {start.set(line.start); end.set(line.end);}
GLuint GLuint end
Definition: SDL_opengl.h:1571
GLuint start
Definition: SDL_opengl.h:1571

Member Data Documentation

◆ end

template<class T>
vector3d<T> irr::core::line3d< T >::end

End point of line.

Definition at line 132 of file line3d.h.

◆ start

template<class T>
vector3d<T> irr::core::line3d< T >::start

Start point of line.

Definition at line 130 of file line3d.h.


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