我有一个带有整数坐标的2D平面图。
在此计划中,有很多要点,分为三类。
首先,我想做的是弄清(是/否)这两组人是否在分开的半球中。
如果您可以通过“源”划一条线(图像中为蓝色),以便所有善良的一面都在一侧,而所有邪恶的另一面都在一侧,则可以将它们视为不同的半球。如果不能将任一组中的任何一个与其他组放在同一侧,那是错误的。
第二步是弄清楚该半球的角度。在第一个示例(如下)中,我绘制了一个180度角(直线),但是我想计算出最不平衡的角(接近0),可以完美地将组分开。这条线将是从源头开始到无限远的两条半线。我想知道使第一个测试为真的最小角度(因此,从逻辑上讲,如果您测量另一侧,则最大角度)
例子:
Right now I am able, through code, to calculate the angle between every individual point and the source. I am stuck at figuring out how to test the "togetherness" of the groups, and most importantly, the absence of a member of the other group in between.
I am working in C#, but this question is really more about the algorithm (I can't think of a working one), so I will accept any answer that solves the problem in any (readable) language, including pseudo-code or straight up text explanation.
All of the points are, in context, complex objects that include a X and a Y coordinate. The other attributes are irrelevant to the question as they are already separated in the required groups (origin is alone and there are two lists for the rest).
您可以排序和扫描。让我们介绍极坐标系统,其原点位于“原点”和任意轴上。
azimuth
每个点(好坏)azimuth
,例如2
或更少不错的邪恶或邪恶尼斯之间transistion; 返回true
,否则false
例如(让方位角以度为单位)
{nice, 12}
{nice, 13}
{nice, 15}
{nice, 21} // nice to evil transition
{evil, 47}
{evil, 121}
{evil, 133} // evil to nice transition
{nice, 211}
{nice, 354}
我们有两个转换,答案是true
。
{nice, 12}
{nice, 13}
{nice, 15} // nice to evil transition
{evil, 121}
{evil, 349}
仅一种过渡,答案是肯定的
{nice, 12}
{nice, 13} // nice to evil transition
{evil, 121} // evil to nice transition
{nice, 15} // nice to evil transition
{evil, 121} // evil to nice transition
{nice, 349}
四个过渡点不能分开,答案是 false
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句