Cheetah Software  1.0
CollisionMesh< T > Class Template Reference

#include <CollisionMesh.h>

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

Public Member Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW CollisionMesh (const T &mu, const T &restitution, const T &grid, const Vec3< T > &left_corner_loc, const DMat< T > &height_map)
 
virtual ~CollisionMesh ()
 
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 > _left_corner_loc
 
DMat< T > _height_map
 
_grid
 
_x_max
 
_y_max
 

Additional Inherited Members

- Protected Attributes inherited from Collision< T >
_mu
 
_restitution_coeff
 

Detailed Description

template<typename T>
class CollisionMesh< T >

Class to represent box collision

Definition at line 17 of file CollisionMesh.h.

Constructor & Destructor Documentation

template<typename T >
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CollisionMesh< T >::CollisionMesh ( const T &  mu,
const T &  restitution,
const T &  grid,
const Vec3< T > &  left_corner_loc,
const DMat< T > &  height_map 
)
inline

Construct a new collision Mesh

Parameters
mu: coefficient of friction
restitution: rebounding ratio (v+/v-)
grid: grid size (meter) of the given height map
left_corner_loc: global location of left bottom edge of the height map
height_map: Height map of mesh

Definition at line 30 of file CollisionMesh.h.

References CollisionMesh< T >::_grid, CollisionMesh< T >::_height_map, CollisionMesh< T >::_x_max, and CollisionMesh< T >::_y_max.

32  : Collision<T>(mu, restitution),
33  _left_corner_loc(left_corner_loc),
34  _height_map(height_map),
35  _grid(grid) {
36  _x_max = (_height_map.rows() - 1) * _grid;
37  _y_max = (_height_map.cols() - 1) * _grid;
38  }
Vec3< T > _left_corner_loc
Definition: CollisionMesh.h:47
DMat< T > _height_map
Definition: CollisionMesh.h:48
template<typename T >
virtual CollisionMesh< T >::~CollisionMesh ( )
inlinevirtual

Definition at line 40 of file CollisionMesh.h.

References CollisionMesh< T >::ContactDetection().

40 {}

+ Here is the call graph for this function:

Member Function Documentation

template<typename T >
bool CollisionMesh< 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 9 of file CollisionMesh.cpp.

10  {
11  // Contact detection
12  Vec3<T> cp_pos_in_height_map = cp_pos - _left_corner_loc;
13  if ((0 < cp_pos_in_height_map[0]) && (cp_pos_in_height_map[0] < _x_max)) {
14  if ((0 < cp_pos_in_height_map[1]) && (cp_pos_in_height_map[1] < _y_max)) {
15  int x_idx = floor(cp_pos_in_height_map[0] / _grid);
16  int y_idx = floor(cp_pos_in_height_map[1] / _grid);
17 
18  Vec3<T> vec1;
19  vec1[0] = _grid;
20  vec1[1] = _grid;
21  vec1[2] = _height_map(x_idx + 1, y_idx + 1) - _height_map(x_idx, y_idx);
22 
23  Vec3<T> vec2;
24  vec2[0] = _grid;
25  vec2[1] = -_grid;
26  vec2[2] = _height_map(x_idx + 1, y_idx) - _height_map(x_idx, y_idx + 1);
27 
28  vec1.normalize();
29  vec2.normalize();
30 
31  Vec3<T> normal = vec2.cross(vec1);
32  // vec2 is x axis
33  Vec3<T> y_axis = normal.cross(vec2);
34 
35  cp_frame.template block<3, 1>(0, 0) = vec2;
36  cp_frame.template block<3, 1>(0, 1) = y_axis;
37  cp_frame.template block<3, 1>(0, 2) = normal;
38 
39  // Vector pointing middle of four points
40  T height_ave = 0.25 * _height_map(x_idx, y_idx) +
41  0.25 * _height_map(x_idx, y_idx + 1) +
42  0.25 * _height_map(x_idx + 1, y_idx) +
43  0.25 * _height_map(x_idx + 1, y_idx + 1);
44 
45  Vec3<T> middle_pt;
46  middle_pt[0] = _grid * x_idx + 0.5 * _grid;
47  middle_pt[1] = _grid * y_idx + 0.5 * _grid;
48  middle_pt[2] = height_ave;
49 
50  Vec3<T> local_diff =
51  cp_frame.transpose() * (cp_pos_in_height_map - middle_pt);
52 
53  if (local_diff[2] < 0.) {
54  penetration = local_diff[2];
55  return true;
56  }
57  }
58  }
59 
60  return false;
61 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
Vec3< T > _left_corner_loc
Definition: CollisionMesh.h:47
DMat< T > _height_map
Definition: CollisionMesh.h:48

+ Here is the caller graph for this function:

Member Data Documentation

template<typename T >
T CollisionMesh< T >::_grid
private

Definition at line 50 of file CollisionMesh.h.

template<typename T >
DMat<T> CollisionMesh< T >::_height_map
private

Definition at line 48 of file CollisionMesh.h.

template<typename T >
Vec3<T> CollisionMesh< T >::_left_corner_loc
private

Definition at line 47 of file CollisionMesh.h.

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

Definition at line 45 of file CollisionMesh.h.

template<typename T >
T CollisionMesh< T >::_x_max
private

Definition at line 51 of file CollisionMesh.h.

template<typename T >
T CollisionMesh< T >::_y_max
private

Definition at line 52 of file CollisionMesh.h.


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