我需要从C++中提取一个多功能。 我在病媒中设定随机点,然后通过线上将其连接起来。 但有时这些界线相互交织,我也这样做。
Is there any formula or something like that, so that the lines wouldn t cross?
这里是法典的一部分:
void draw_picture(Canvas & canvas) {
PairXY a,b,c,d,e;
int k;
vector <PairXY> vertex;
vertex.push_back(PairXY(drandom(k),drandom(k)));
vertex.push_back(PairXY(drandom(k),drandom(k)));
vertex.push_back(PairXY(drandom(k),drandom(k)));
vertex.push_back(PairXY(drandom(k),drandom(k)));
vertex.push_back(PairXY(drandom(k),drandom(k)));
vector <PairXY>::const_iterator iter;
iter = vertex.begin();
a=*iter;
iter = vertex.begin()+1;
b=*iter;
iter = vertex.begin()+2;
c=*iter;
iter = vertex.begin()+3;
d=*iter;
iter = vertex.begin()+4;
e=*iter;
Line l1(a,b);
draw_line(l1,canvas);
Line l2(b,c);
draw_line(l2,canvas);
Line l3(c,d);
draw_line(l3,canvas);
Line l4(d,e);
draw_line(l4,canvas);
Line l5(e,a);
draw_line(l5,canvas);
}