# c# 求范围问题

0

``````               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);
}
}
}
``````

0

0

您需要登录以后才能回答，未注册用户请先注册