template<typename T> struct Point3_ {
Point3_() : x(0), y(0), z(0) {}
Point3_(T _x, T _y, T _z) : x(_x), y(_y), z(_z) {}
T x;
T y;
T z;
};
typedef Point3_<int> Point3I;
typedef Point3_<float> Point3F;
typedef Point3_<double> Point3D;
bool Esvi3DGraph::PointInPolygon(
const std::vector<Point3D> &points, const Point3D &testPoint) {
int i = 0, j = 0;
bool result = false;
int size = points.size();
double testX = testPoint.x;
double testY = testPoint.y;
for (i = 0, j = size - 1; i < size; j = i++) {
const Point3D &vertI = points[i];
const Point3D &vertJ = points[j];
if (((vertI.y > testY) != (vertJ.y > testY)) &&
(testX < (vertJ.x - vertI.x) * (testY - vertI.y) / (vertJ.y - vertI.y) +
vertI.x))
result = !result;
}
return result;
}
来源:oschina
链接:https://my.oschina.net/u/221120/blog/4290514