首页 新闻 会员 周边 捐助

c# 求范围问题

0
悬赏园豆:10 [待解决问题]

请教一下,下面的这段代码是做什么的?求最大范围?如果是求最大范围前两行不就行了吗

第一行已经是x1、x2的最大值了,第三行又是什么意思呢?

               double x1_ = Math.Max(x1, x2);
                double x1__ = Math.Min(x1, x2);
                double x11 = Math.Max(x1_, x2);
                double x12 = Math.Min(x1__, x2);
                int n = 1000000;
                double h = (x11 - x12) / n;


                for (int j = 0; j < n; j++)
                {
                    x12 = x12 + h;
                    double A, B;
                    double A1 = 0, B1 = 0;
                    if (x1 <= x12)
                    {
                        if (x12 <= x2 && x12 <= x3)
                        {
                            A = (y3 - y1) / (x3 - x1) * (x12 - x1) + y1;
                            B = (y2 - y1) / (x2 - x1) * (x12 - x1) + y1;
                            A1 = Math.Max(A, B);
                            B1 = Math.Min(A, B);
                        }
                    else if (x12 > x2 || x12 > x3)
                    {
                        if (x2 < x3)
                        {
                            A = (y3 - y1) / (x3 - x1) * (x12 - x1) + y1;
                            B = (y3 - y2) / (x3 - x2) * (x12 - x2) + y2;
                            A1 = Math.Max(A, B);
                            B1 = Math.Min(A, B);
                         }
                         else
                         {
                            A = (y2 - y1) / (x2 - x1) * (x12 - x1) + y1;
                            B = (y3 - y2) / (x3 - x2) * (x12 - x2) + y2;
                            A1 = Math.Max(A, B);
                            B1 = Math.Min(A, B);
                          }
                     }
                    }
                    if (x2 <= x12)
                    {
                        if (x12 <= x1 && x12 <= x3)
                        {
                            A = (y3 - y2) / (x3 - x2) * (x12 - x2) + y2;
                            B = (y1 - y2) / (x1 - x2) * (x12 - x2) + y2;
                            A1 = Math.Max(A, B);
                            B1 = Math.Min(A, B);
                        }
                        else if (x12 > x1 || x12 > x3)
                        {
                            if (x1 < x3)
                            {
                                A = (y3 - y2) / (x3 - x2) * (x12 - x2) + y2;
                                B = (y3 - y1) / (x3 - x1) * (x12 - x1) + y1;
                                A1 = Math.Max(A, B);
                                B1 = Math.Min(A, B);
                            }
                            else
                            {
                                A = (y1 - y2) / (x1 - x2) * (x12 - x2) + y2;
                                B = (y3 - y1) / (x3 - x1) * (x12 - x1) + y1;
                                A1 = Math.Max(A, B);
                                B1 = Math.Min(A, B);
                            }
                        }
                    }
                    if (x3 <= x12)
                    {
                        if (x12 <= x2 && x12 <= x3)
                        {
                            A = (y1 - y3) / (x1 - x3) * (x12 - x3) + y3;
                            B = (y2 - y3) / (x2 - x3) * (x12 - x3) + y3;
                            A1 = Math.Max(A, B);
                            B1 = Math.Min(A, B);
                        }
                        else if (x12 > x2 || x12 > x3)
                        {
                            if (x2 < x3)
                            {
                                A = (y1 - y3) / (x1 - x3) * (x12 - x3) + y3;
                                B = (y1 - y2) / (x1 - x2) * (x12 - x2) + y2;
                                A1 = Math.Max(A, B);
                                B1 = Math.Min(A, B);
                            }
                            else
                            {
                                A = (y2 - y3) / (x2 - x3) * (x12 - x3) + y3;
                                B = (y1 - y2) / (x1 - x2) * (x12 - x2) + y2;
                                A1 = Math.Max(A, B);
                                B1 = Math.Min(A, B);
                            }
                        }
                    }
c#
清风配酒的主页 清风配酒 | 初学一级 | 园豆:21
提问于:2020-04-27 18:20
< >
分享
所有回答(2)
0

感觉不用细研究,知道没用就行了

猝不及防 | 园豆:2836 (老鸟四级) | 2020-04-28 09:20
0

写错了吧可能是

会长 | 园豆:12461 (专家六级) | 2020-04-28 09:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册