ContEllipsoid3MinCR<Real>::ContEllipsoid3MinCR (int numPoints, const Vector3<Real>* points, const Vector3<Real>& C, const Matrix3<Real>& R, Real D[3]) { // Compute the constraint coefficients, of the form (A[0],A[1]) for // each i. std::vector<Vector3<Real> > A(numPoints); for (int i = 0; i < numPoints; ++i) { Vector3<Real> diff = points[i] - C; // P[i] - C Vector3<Real> prod = diff*R; // R^T*(P[i] - C) = (u,v,w) A[i].X() = prod.X()*prod.X(); // u^2 A[i].Y() = prod.Y()*prod.Y(); // v^2 A[i].Z() = prod.Z()*prod.Z(); // w^2 } // TODO: Sort the constraints to eliminate redundant ones. It is clear // how to do this in ContEllipse2MinCR. How to do this in 3D? MaxProduct(A, D); }
ContEllipse2MinCR<Real>::ContEllipse2MinCR (int numPoints, const Vector2<Real>* points, const Vector2<Real>& C, const Matrix2<Real>& R, Real D[2]) { // Compute the constraint coefficients, of the form (A[0],A[1]) for // each i. std::vector<Vector2<Real> > A(numPoints); for (int i = 0; i < numPoints; ++i) { Vector2<Real> diff = points[i] - C; // P[i] - C Vector2<Real> prod = diff*R; // R^T*(P[i] - C) = (u,v) A[i].X() = prod.X()*prod.X(); // u^2 A[i].Y() = prod.Y()*prod.Y(); // v^2 } // Sort to eliminate redundant constraints. typename std::vector<Vector2<Real> >::iterator end; // Lexicographical sort, (x0,y0) > (x1,y1) if x0 > x1 or if x0 = x1 and // y0 > y1. Remove all but first entry in blocks with x0 = x1 since the // corresponding constraint lines for the first entry "hides" all the // others from the origin. std::sort(A.begin(), A.end(), XGreater); end = std::unique(A.begin(), A.end(), XEqual); A.erase(end, A.end()); // Lexicographical sort, (x0,y0) > (x1,y1) if y0 > y1 or if y0 = y1 and // x0 > x1. Remove all but first entry in blocks with y0 = y1 since the // corresponding constraint lines for the first entry "hides" all the // others from the origin. std::sort(A.begin(), A.end(), YGreater); end = std::unique(A.begin(), A.end(), YEqual); A.erase(end, A.end()); MaxProduct(A, D); }
int main() { printf("maxProduct = %d\n",MaxProduct()); return 0; }