#ifndef ICL_CONVEX_HULL_MONOTONE_CHAIN_H #define ICL_CONVEX_HULL_MONOTONE_CHAIN_H #include #include namespace icl{ /// Utility Structure used for the Convex-Hull Algorithm struct CHPoint{ CHPoint(float x=0, float y=0, Vec *v=0):x(x),y(y),v(v){} float x,y; Vec *v; inline bool operator<(const CHPoint &p) const{ if(y==p.y) return x0 for P2 left of the line through P0 and P1 =0 for P2 on the line <0 for P2 right of the line See: the January 2001 Algorithm on Area of Triangles **/ inline float isLeft(const CHPoint P0, const CHPoint P1, const CHPoint P2){ return (P1.x - P0.x)*(P2.y - P0.y) - (P2.x - P0.x)*(P1.y - P0.y); } ///chainHull_2D(): Andrew's monotone chain 2D convex hull algorithm /** Input: P[] = an array of 2D points presorted by increasing x- and y-coordinates \n To be used: this ordering: \code inline bool operator<(const CHPoint &p) const{ if(y==p.y) return x convexHull(std::vector P); } #endif