GCOP
1.0
|
00001 #ifndef GCOP_CYLINDER_H 00002 #define GCOP_CYLINDER_H 00003 00004 #include "constraint.h" 00005 00006 namespace gcop { 00007 00008 template <typename T = VectorXd, 00009 int _nx = Dynamic, 00010 int _nu = Dynamic, 00011 int _np = Dynamic> 00012 class Cylinder : public Constraint<T, _nx, _nu, _np, 1> { 00013 public: 00014 00015 typedef Matrix<double, 1, 1> Vectorgd; 00016 typedef Matrix<double, 1, _nx> Matrixgxd; 00017 typedef Matrix<double, 1, _nu> Matrixgud; 00018 typedef Matrix<double, 1, _np> Matrixgpd; 00019 00020 typedef Matrix<double, _nx, 1> Vectornd; 00021 typedef Matrix<double, _nu, 1> Vectorcd; 00022 typedef Matrix<double, _np, 1> Vectormd; 00023 00024 00025 Cylinder(const Vector3d &o, double r, double h, double cr = .5); 00026 00027 bool operator()(Vectorgd &g, 00028 double t, const T &x, const Vectorcd &u, 00029 const Vectormd *p = 0, 00030 Matrixgxd *dgdx = 0, Matrixgud *dgdu = 0, 00031 Matrixgpd *dgdp = 0); 00032 00033 Vector3d o; 00034 double r; 00035 double h; 00036 double cr; 00037 00038 }; 00039 00040 00041 template <typename T, int _nx, int _nu, int _np> 00042 Cylinder<T, _nx, _nu, _np>::Cylinder(const Vector3d &o, double r, double h, double cr) : 00043 Constraint<T, _nx, _nu, _np, 1>(), o(o), r(r), h(h), cr(cr) 00044 { 00045 } 00046 00047 template <typename T, int _nx, int _nu, int _np> 00048 bool Cylinder<T, _nx, _nu, _np>::operator()(Vectorgd &g, 00049 double t, const T &x, const Vectorcd &u, 00050 const Vectormd *rho, 00051 Matrixgxd *dgdx, Matrixgud *dgdu, 00052 Matrixgpd *dgdp) 00053 { 00054 const Vector3d &p = x.second.head(3); // position 00055 00056 Vector2d v = p.head<2>() - o.head<2>(); 00057 00058 double d = v.norm() - cr; // distance from center of cylinder to system boundary 00059 00060 if (d < 0) { 00061 cout << "ERR: already colliding" << endl; 00062 } 00063 00064 g[0] = r - d; // must be negative for non-collision 00065 00066 if (dgdx) { 00067 dgdx->Zero(); 00068 if (g[0] > 0) 00069 dgdx->head(2) = -v/v.norm(); 00070 else 00071 dgdx->head(2) = v/v.norm(); 00072 } 00073 } 00074 }; 00075 00076 00077 00078 #endif