我正在使用沃罗诺伊多边形来布置我的地图,我有一个返回多边形边缘列表的函数,所以当绘制边缘时看起来像这样这样,这是我的目标。然而,我需要存储有关每个单独多边形的信息,例如它持有的地形类型,但为此我需要仅凭边缘列表构建多边形。我的问题是如何从边缘列表构建这些多边形?
我可以提供伪代码、C++或Objective-C。
我可以提供伪代码、C++或Objective-C。
class Point {int x, y;}
class Vector
{
Point StartPoint, EndPoint;
Contains(Vector vector)
{
return StartPoint == vector || EndPoint == vector;
}
}
class Polygon /*Array of Vectors */
{
TopVector /* Last vector to be added */
}
Polygon findPolygon(Vector startVector)
Polygon returnValue = new Polygon(startVector);
do
{
Polygon.Add(getLowestDotProduct(vector, getConnectingVectors(vector, vector.EndPoint)))
} while (!Polygon.TopVector.Contains(startVector));
}
Point [] getConnectingVectors(Vector vector, endPoint)
{
//find all vectors that start or end at endPoint
}
Vector getLowestDotProduct(Vector startVector, Vector[] connectedVectors)
{
// get the lowest dot product
}