请教一下,下面的这段代码是做什么的?求最大范围?如果是求最大范围前两行不就行了吗
第一行已经是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);
}
}
}
感觉不用细研究,知道没用就行了
写错了吧可能是