ray3.cpp
Go to the documentation of this file.
1 
7 #include "ray3.h"
8 #include "plane.h"
9 
10 namespace argos {
11 
12  /****************************************/
13  /****************************************/
14 
15  bool CRay3::Intersects(const CPlane& c_plane,
16  CVector3& c_point) const {
17  CVector3 cRayVec;
18  Real fDen = c_plane.GetNormal().DotProduct(ToVector(cRayVec));
19  if(Abs(fDen) > 0.0f) {
20  /* There could be intersection */
21  Real fTOnRay = -c_plane.GetNormal().DotProduct(m_cStart - c_plane.GetPosition()) / fDen;
22  if(fTOnRay < 0.0f || fTOnRay > 1.0f) {
23  /* Intersection point is beyond ray extrema */
24  return false;
25  }
26  else {
27  /* There is an intersection */
28  GetPoint(c_point, fTOnRay);
29  return true;
30  }
31  }
32  else {
33  /* No intersection */
34  return false;
35  }
36  }
37 
38  /****************************************/
39  /****************************************/
40 
41 }
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
T Abs(const T &t_v)
Returns the absolute value of the passed argument.
Definition: general.h:25
const CVector3 & GetPosition() const
Definition: plane.h:39
const CVector3 & GetNormal() const
Definition: plane.h:47
bool Intersects(const CPlane &c_plane, CVector3 &c_point) const
Definition: ray3.cpp:15
void GetPoint(CVector3 &c_point, Real f_t) const
Definition: ray3.h:109
CVector3 & ToVector(CVector3 &c_buffer) const
Definition: ray3.h:100
A 3D vector class.
Definition: vector3.h:31
Real DotProduct(const CVector3 &c_vector3) const
Returns the dot product between this vector and the passed one.
Definition: vector3.h:369