生成泰森多边形

void ConvexHull(Point[] pts)
        {
            int[][] temp = new int[pts.Length][];
            for (int i = 0; i < pts.Length; i++)
            {
                temp[i] = new int[2];
                temp[i][0] = (int)(pts[i].X + pts[i].Y);
                temp[i][1] = (int)(pts[i].X - pts[i].Y);
            }

            List<int[]> ls = temp.ToList();
            int max1index = ls.FindIndex(o => o[0] == ls.Max(j => j[0]));
            int max2index = ls.FindIndex(o => o[1] == ls.Max(j => j[1]));
            int min1index = ls.FindIndex(o => o[0] == ls.Min(j => j[0]));
            int min2index = ls.FindIndex(o => o[1] == ls.Min(j => j[1]));
            Console.Write(string.Format("{0},{1},{2},{3}", max1index, min1index, max2index, min2index));
	//找出点集中,最靠近点集四至的点。为了简化操作,我将点集pts的四至角点都加入了点集中,避免了外围凸包的复杂度和Voronoi切分时考虑边界

            List<Point> tubao = new List<Point>();
            List<Point> other = new List<Point>();

	//根据最右原则,求取凸包点列表。如果像我之前将四至角点加入点集,这部分可以除去,直接构建凸包点列表
            Point Pi, Pj, Pk;

            int st = max1index, ed = max2index;
            Pk = pts[st];
            Pi = Pk;
            Pj = pts[ed];

            do
            {
                if (tubao.Count > 0)
                    Pj = Pk;

                con:
                bool right = false;
                List<Point> rightpt = new List<Point>();

                rightpt.Clear();
                for (int i = 0; i < pts.Length; i++)
                {
                    if (pts[i].Equals(Pi)) continue;
                    if (pts[i].Equals(Pj)) continue;
                    int re = getPtDirection(Pi, Pj, pts[i]);
                    if (re > 0)
                    {
                        right = true;
                        rightpt.Add(pts[i]);
                    }
                    else if (re == 0)
                    {
                        //共线
                        right = false;
                    }
                    else
                    {
                        right = false;
                    }
                }

                if (rightpt.Count == 0)
                {
                    //更改后继点
                    tubao.Add(Pi);
                    Pi = Pj;
                    continue;
                }
                else
                {
                    List<double> rlen = new List<double>(rightpt.Count);
                    foreach (var pt in rightpt)
                    {
                        rlen.Add(pt2lnDis(pt, Pi, Pj));
                    }
                    int index = rlen.FindIndex(o => o == rlen.Max());

                    Pj = rightpt[index];
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值