ARGoS  3
A parallel, multi-engine simulator for swarm robotics
plane.cpp
Go to the documentation of this file.
1 #include "plane.h"
2 #include "ray3.h"
3 
4 namespace argos {
5 
6  /****************************************/
7  /****************************************/
8 
9  bool CPlane::Intersects(Real& f_t_on_ray,
10  const CRay3& c_ray) {
11  /* Ray direction */
12  CVector3 cRayDir;
13  c_ray.GetDirection(cRayDir);
14  /* Calculate f_t_on_ray */
15  Real fNumerator = (m_cPosition-c_ray.GetStart()).DotProduct(m_cNormal);
16  Real fDenominator = cRayDir.DotProduct(m_cNormal);
17  /* Is ray parallel to plane? */
18  if(Abs(fDenominator) > 1e-6) {
19  /* No, it's not */
20  f_t_on_ray = fNumerator / fDenominator / c_ray.GetLength();
21  return (f_t_on_ray < 1.0f);
22  }
23  else {
24  /* Yes, it is */
25  /* Is ray coincident with the plane? */
26  if(Abs(fNumerator) > 1e-6) {
27  /* No, the ray is parallel to and far from the plane */
28  /* No intersection possible */
29  return false;
30  }
31  else {
32  /* Yes, the ray coincides with the plane */
33  f_t_on_ray = 0.0f;
34  return true;
35  }
36  }
37  }
38 
39  /****************************************/
40  /****************************************/
41 
42 }
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CVector3
A 3D vector class.
Definition: vector3.h:29
plane.h
argos::CRay3
Definition: ray3.h:19
argos::Abs
T Abs(const T &t_v)
Returns the absolute value of the passed argument.
Definition: general.h:25
argos::CPlane::Intersects
bool Intersects(Real &f_t_on_ray, const CRay3 &c_ray)
Definition: plane.cpp:9
argos::CRay3::GetStart
CVector3 & GetStart()
Definition: ray3.h:37
argos::CRay3::GetDirection
void GetDirection(CVector3 &c_buffer) const
Definition: ray3.h:80
ray3.h
argos::CRay3::GetLength
Real GetLength() const
Definition: ray3.h:96
Real
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
argos::CVector3::DotProduct
Real DotProduct(const CVector3 &c_vector3) const
Returns the dot product between this vector and the passed one.
Definition: vector3.h:348