Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00496_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00496_source.php on line 2
The ARGoS Website

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  void CPlane::SetFromThreePoints(const CVector3& c_point_1,
10  const CVector3& c_point_2,
11  const CVector3& c_point_3) {
12  m_cNormal = CVector3(c_point_3 - c_point_2);
13  m_cNormal.CrossProduct(c_point_1 - c_point_2);
14  m_cNormal.Normalize();
15  m_cPosition = c_point_2;
16  }
17 
18  /****************************************/
19  /****************************************/
20 
21  bool CPlane::Intersects(Real& f_t_on_ray,
22  const CRay3& c_ray) {
23  /* Ray direction */
24  CVector3 cRayDir;
25  c_ray.GetDirection(cRayDir);
26  /* Calculate f_t_on_ray */
27  Real fNumerator = (m_cPosition-c_ray.GetStart()).DotProduct(m_cNormal);
28  Real fDenominator = cRayDir.DotProduct(m_cNormal);
29  /* Is ray parallel to plane? */
30  if(Abs(fDenominator) > 1e-6) {
31  /* No, it's not */
32  f_t_on_ray = fNumerator / fDenominator / c_ray.GetLength();
33  return (f_t_on_ray < 1.0f);
34  }
35  else {
36  /* Yes, it is */
37  /* Is ray coincident with the plane? */
38  if(Abs(fNumerator) > 1e-6) {
39  /* No, the ray is parallel to and far from the plane */
40  /* No intersection possible */
41  return false;
42  }
43  else {
44  /* Yes, the ray coincides with the plane */
45  f_t_on_ray = 0.0f;
46  return true;
47  }
48  }
49  }
50 
51  /****************************************/
52  /****************************************/
53 
54 }
A 3D vector class.
Definition: vector3.h:29
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
T Abs(const T &t_v)
Returns the absolute value of the passed argument.
Definition: general.h:25
bool Intersects(Real &f_t_on_ray, const CRay3 &c_ray)
Definition: plane.cpp:21
CVector3 & GetStart()
Definition: ray3.h:37
void GetDirection(CVector3 &c_buffer) const
Definition: ray3.h:80
Real GetLength() const
Definition: ray3.h:96
Real DotProduct(const CVector3 &c_vector3) const
Returns the dot product between this vector and the passed one.
Definition: vector3.h:348
CVector3 & CrossProduct(const CVector3 &c_vector3)
Calculates the cross product between this vector and the passed one.
Definition: vector3.h:361
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
CVector3 & Normalize()
Normalizes this vector.
Definition: vector3.h:215
void SetFromThreePoints(const CVector3 &c_point_1, const CVector3 &c_point_2, const CVector3 &c_point_3)
Definition: plane.cpp:9