/// <summary>
/// 多边形点集排序
/// </summary>
/// <param name="vPoints"></param>
/// <returns></returns>
public List<Point> SortPolyPoints(List<Point> vPoints)
{
if (vPoints == null || vPoints.Count == 0) return null;
//计算重心
Point center = new Point();
double X = 0, Y = 0;
for (int i = 0; i < vPoints.Count; i++)
{
X += vPoints[i].X;
Y += vPoints[i].Y;
}
center = new Point((int)X / vPoints.Count, (int)Y / vPoints.Count, vPoints[0].Z);
//冒泡排序
for (int i = 0; i < vPoints.Count - 1; i++)
{
for (int j = 0; j < vPoints.Count - i - 1; j++)
{
if (PointCmp(vPoints[j], vPoints[j + 1], center))
{
Point tmp = vPoints[j];
vPoints[j] = vPoints[j + 1];
vPoints[j + 1] =
unity 凸多形顶点排序
最新推荐文章于 2024-05-02 18:31:14 发布
本文介绍如何使用重心计算和冒泡排序算法对多边形点集进行排序,通过PointCmp函数判断点的相对位置。核心在于利用向量交叉和距离比较确定点的顺序。

最低0.47元/天 解锁文章
2308

被折叠的 条评论
为什么被折叠?



