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


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

            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 += " ";
                }
                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));
            }
        运行如图一:


        //从左下角到右上角调用
            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));
            }
        运行如图二:

  • 相关阅读:
    6)图[5]最短路径
    6)图[4]关键路径
    6)图[3]拓扑排序算法
    6)图[2]Prim算法[最小生成树]
    Aprori算法[关联规则算法]
    K-Modes算法[聚类算法]
    linux Centos6.7 python交互模式下回退异常问题解决
    Python-面向对象(二)-Day7
    Python-面向对象(一)-Day7
    (error) MISCONF Redis is configured to save RDB snapshots
  • 原文地址:https://www.cnblogs.com/dooroo/p/EntryName.html
Copyright © 2020-2023  润新知