首页 > 其他 > 详细

己知矩形两对角点坐标,计算矩形区域内所有坐标

时间:2014-07-16 18:15:35      阅读:394      评论:0      收藏:0      [点我收藏+]

时不时要用到求坐标,原来写过又忘了,重写一次备忘

        private string getAllPoint(Point p1, Point p2)
        {
            string info = "";
            int minNumX = 0;
            int minNumY = 0;
            for (int i = 0; i < Math.Abs(p2.X - p1.X) + 1; i++)
            {
                minNumX = (int)(p1.X < p2.X ? p1.X : p2.X) + i;
                for (int j = 0; j < Math.Abs(p2.Y - p1.Y) + 1; j++)
                {
                    minNumY = (int)(p1.Y < p2.Y ? p1.Y : p2.Y) + j;
                    info += minNumX.ToString() + "," + minNumY.ToString() + "|";
                }
                info += "\r\n";
            }
            return info;
        }
    //从左上角到右下角调用
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Point p1 = new Point(2, 2);
            Point p2 = new Point(5, 4);
            MessageBox.Show(getAllPoint(p1, p2));
        }
    运行如图一:
bubuko.com,布布扣

    //从左下角到右上角调用
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Point p1 = new Point(3, 2);
            Point p2 = new Point(1, 4);
            MessageBox.Show(getAllPoint(p1, p2));
        }
    运行如图二:

bubuko.com,布布扣

 

己知矩形两对角点坐标,计算矩形区域内所有坐标,布布扣,bubuko.com

己知矩形两对角点坐标,计算矩形区域内所有坐标

原文:http://www.cnblogs.com/dooroo/p/EntryName.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!