对于给定的矩形R1
我试图找出哪些是可以用它相交如果我画一个vectical线段其他矩形。
与相交的矩形R1
被标记为红色。
每个矩形的特征在于其(top, left)
和(bottom, right)
坐标。
R1 = [top, left, bottom, right],...,Rn = [top, left, bottom, right]
通过使用坐标和垂直线。 我想找到与R1相交的矩形
解
我发现下面的库,做同样的工作,正如ICL升压库,但必须简单:下载网站:[ https://github.com/ekg/intervaltree][2]
#include <iostream>
#include <fstream>
#include "IntervalTree.h"
using namespace std;
struct Position
{
int x;
int y;
string id;
};
int main()
{
vector<Interval<Position>> intervals;
intervals.push_back(Interval<Position>(4,10,{1,2,"r1"}));
intervals.push_back(Interval<Position>(6,10,{-6,-3,"r2"}));
intervals.push_back(Interval<Position>(8,10,{5,6,"r3"}));
vector<Interval<Position> > results;
vector<string> value;
int start = 4;
int stop = 10;
IntervalTree<Position> tree(intervals);
// tree.findContained(start, stop, results);
tree.findOverlapping(start, stop, results);
cout << "found " << results.size() << " overlapping intervals" << endl;
}
例
- LEFT = 4;
- RIGHT = 10;
- 结构{1,2, “RC1”};
intervals.push_back(时间间隔(4,10,{1,2, “R1”}));