问题说白了就是:看给定的点在哪两个线段之间。根据题目的描述,给定的点要么在线段左边,要么右边,所以需做一个叉积,来判定点与两条线段的位置关系(具体如下面的FindBelongBinIndex()函数描述)。
因为线段是排好序的了,所以可以二分查找。
#include <iostream>
#include <algorithm>
using namespace std;
struct Point2D
{
Point2D()
{
x=0.0f;
y=0.0f;
}
Point2D(double tx,double ty)
{
x=tx;
y=ty;
}
double x,y;
};
//Return the crossproduct of vec1*vec2
......
阅读全文