English 中文(简体)
• 如何在C++中提取一环形,使线路不会交叉?
原标题:How to draw a polygon in C++ such that the lines do not intersect?
  • 时间:2011-11-23 00:03:35
  •  标签:
  • c++
  • polygon

我需要从C++中提取一个多功能。 我在病媒中设定随机点,然后通过线上将其连接起来。 但有时这些界线相互交织,我也这样做。

“entergraph

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);
}
最佳回答

它与你可能期望的“基本”一样(而不是“Complex”)。 Polygon:

http://en.wikipedia.org/wiki/Simple_polygon

这不一定是一个独特的解决办法:

Sort Point list into polygon

因此,各点或路段的顺序通常在多角绘图发动机中。 如果你是这样有条不紊的,可以找到至少一个。 a. 一套要点的非复合体:

http://www.computational-geometry.org/mailing-lists/compgeom-announce/2003-March/000727.html

http://www.coutilal-geometry.org/mailing-lists/compgeom-announce/2003-March/000732.html


其他人指出,你的法典是重复的。 你在所分享的节选中也没有对<条码>k

void draw_picture(Canvas & canvas, int k, int numVertices = 5) {
  vector<PairXY> vertices;
  for (int index = 0; index < numVertices; index++) { 
      vertices.push_back(PairXY(drandom(k),drandom(k)));
  }

  vector<PairXY>::const_iterator iter = vertices.begin();
  while (iter != vertices.end()) {
     PairXY startPoint = *iter;
     iter++;
     if (iter == vertices.end()) {
         Line edgeLine (startPoint, vertices[0]);
         draw_line(edgeLine, canvas);
     } else {
         Line edgeLine (startPoint, *iter);
         draw_line(edgeLine, canvas);
     }
   }
}

在C++中有许多管理频率的方法,尽管其中许多比其他语文的对应单位更平均。 最近,在C++11中添加了一条:>,但你的建筑环境尚未支持。

问题回答

sort the array before drawing it

Find the left most point than go CCW from there

ie leftmost where point y < first point y until none found

直至无发现





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签