Cheetah Software  1.0
CollisionBox< T > Class Template Reference

#include <CollisionBox.h>

+ Inheritance diagram for CollisionBox< T >:
+ Collaboration diagram for CollisionBox< T >:

Public Member Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW CollisionBox (const T &mu, const T &restitution, const T &depth, const T &width, const T &height, const Vec3< T > &position, const Mat3< T > &ori)
 
virtual ~CollisionBox ()
 
virtual bool ContactDetection (const Vec3< T > &cp_pos, T &penetration, Mat3< T > &cp_frame)
 
- Public Member Functions inherited from Collision< T >
 Collision (const T &mu, const T &resti)
 
virtual ~Collision ()
 
const T & getFrictionCoeff ()
 
const T & getRestitutionCoeff ()
 

Private Attributes

_size [3]
 
Vec3< T > _position
 
Mat3< T > _orientation
 

Additional Inherited Members

- Protected Attributes inherited from Collision< T >
_mu
 
_restitution_coeff
 

Detailed Description

template<typename T>
class CollisionBox< T >

Class to represent box collision

Definition at line 17 of file CollisionBox.h.

Constructor & Destructor Documentation

template<typename T >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CollisionBox< T >::CollisionBox ( const T &  mu,
const T &  restitution,
const T &  depth,
const T &  width,
const T &  height,
const Vec3< T > &  position,
const Mat3< T > &  ori 
)
inline

Construct a new collision box

Parameters
mu: coefficient of friction
restitution: rebounding ratio (v+/v-)
depth: depth of the box
width: width of the box
height: height of the box
position: position of the box w.r.t the global frame
ori: orientation of the box w.r.t the global frame

Definition at line 31 of file CollisionBox.h.

References CollisionBox< T >::_size.

34  : Collision<T>(mu, restitution), _position(position), _orientation(ori) {
35  _size[0] = depth;
36  _size[1] = width;
37  _size[2] = height;
38  }
Vec3< T > _position
Definition: CollisionBox.h:47
Mat3< T > _orientation
Definition: CollisionBox.h:48
template<typename T >
virtual CollisionBox< T >::~CollisionBox ( )
inlinevirtual

Definition at line 40 of file CollisionBox.h.

References CollisionBox< T >::ContactDetection().

40 {}

+ Here is the call graph for this function:

Member Function Documentation

template<typename T >
bool CollisionBox< T >::ContactDetection ( const Vec3< T > &  cp_pos,
T &  penetration,
Mat3< T > &  cp_frame 
)
virtual

check whether the contact happens or not cp_frame let you know which direction is normal (z) and which directions are x and y. The frame is basically contact coordinate w.r.t global.

Implements Collision< T >.

Definition at line 10 of file CollisionBox.cpp.

11  {
12  Vec3<T> center2cp_local = _orientation.transpose() * (cp_pos - _position);
13 
14  bool inside_box(true);
15  T err[3] = {0};
16  for (size_t i(0); i < 3; ++i) {
17  // Outside to the positive direction
18  if (center2cp_local[i] > _size[i] / 2.) {
19  inside_box = false;
20  }
21  // Outside to the negative direction
22  else if (center2cp_local[i] < -_size[i] / 2.) {
23  inside_box = false;
24  }
25  // Distance from surface
26  else {
27  err[i] = _size[i] / 2. - std::abs(center2cp_local[i]);
28  }
29  }
30 
31  if (inside_box) {
32  if (err[2] < std::min(err[0], err[1])) { // Contact on Z surface
33  if (center2cp_local[2] > 0.) {
34  cp_frame = _orientation;
35  } else {
36  cp_frame = -_orientation;
37  }
38  penetration = -err[2];
39  } else if (err[1] < std::min(err[0], err[2])) { // Contact on Y surface
40  if (center2cp_local[1] > 0.) {
41  // X -->X
42  cp_frame.template block<3, 1>(0, 0) =
43  _orientation.template block<3, 1>(0, 0);
44  // -Z --> Y
45  cp_frame.template block<3, 1>(0, 1) =
46  -_orientation.template block<3, 1>(0, 2);
47  // Y --> Z
48  cp_frame.template block<3, 1>(0, 2) =
49  _orientation.template block<3, 1>(0, 1);
50  } else {
51  // X --> X
52  cp_frame.template block<3, 1>(0, 0) =
53  _orientation.template block<3, 1>(0, 0);
54  // Z --> Y
55  cp_frame.template block<3, 1>(0, 1) =
56  _orientation.template block<3, 1>(0, 2);
57  // -Y --> Z
58  cp_frame.template block<3, 1>(0, 2) =
59  -_orientation.template block<3, 1>(0, 1);
60  }
61  penetration = -err[1];
62  } else { // contact on X surface
63  if (center2cp_local[0] > 0.) {
64  // X -->X
65  cp_frame.template block<3, 1>(0, 0) =
66  _orientation.template block<3, 1>(0, 1);
67  // -Z --> Y
68  cp_frame.template block<3, 1>(0, 1) =
69  -_orientation.template block<3, 1>(0, 2);
70  // Y --> Z
71  cp_frame.template block<3, 1>(0, 2) =
72  _orientation.template block<3, 1>(0, 0);
73  } else {
74  // X -->X
75  cp_frame.template block<3, 1>(0, 0) =
76  _orientation.template block<3, 1>(0, 0);
77  // -Z --> Y
78  cp_frame.template block<3, 1>(0, 1) =
79  _orientation.template block<3, 1>(0, 1);
80  // Y --> Z
81  cp_frame.template block<3, 1>(0, 2) =
82  -_orientation.template block<3, 1>(0, 0);
83  }
84  penetration = -err[0];
85  }
86  return true;
87  }
88  return false;
89 }
Vec3< T > _position
Definition: CollisionBox.h:47
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
Mat3< T > _orientation
Definition: CollisionBox.h:48

+ Here is the caller graph for this function:

Member Data Documentation

template<typename T >
Mat3<T> CollisionBox< T >::_orientation
private

Definition at line 48 of file CollisionBox.h.

template<typename T >
Vec3<T> CollisionBox< T >::_position
private

Definition at line 47 of file CollisionBox.h.

template<typename T >
T CollisionBox< T >::_size[3]
private

Definition at line 45 of file CollisionBox.h.


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