GCOP
1.0
|
00001 #ifndef GCOP_DISK_H 00002 #define GCOP_DISK_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 Disk : 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 Disk(const Vector2d &o, double r, 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 Vector2d o; 00034 double r; 00035 double cr; 00036 00037 }; 00038 00039 00040 template <typename T, int _nx, int _nu, int _np> 00041 Disk<T, _nx, _nu, _np>::Disk(const Vector2d &o, double r, double cr) : 00042 Constraint<T, _nx, _nu, _np, 1>(), o(o), r(r), cr(cr) 00043 { 00044 } 00045 00046 template <typename T, int _nx, int _nu, int _np> 00047 bool Disk<T, _nx, _nu, _np>::operator()(Vectorgd &g, 00048 double t, const T &x, const Vectorcd &u, 00049 const Vectormd *rho, 00050 Matrixgxd *dgdx, Matrixgud *dgdu, 00051 Matrixgpd *dgdp) 00052 { 00053 const Vector2d &p = x.head(2); // position 00054 00055 Vector2d v = p - o; 00056 00057 double d = v.norm() - cr; // distance from center of disk to system boundary 00058 00059 if (d < 0) { 00060 cout << "ERR: already colliding" << endl; 00061 } 00062 00063 g[0] = r - d; // must be negative for non-collision 00064 00065 if (dgdx) { 00066 dgdx->Zero(); 00067 if (g[0] > 0) 00068 dgdx->head(2) = -v/v.norm(); 00069 else 00070 dgdx->head(2) = v/v.norm(); 00071 } 00072 } 00073 }; 00074 00075 00076 00077 #endif