2 jjt1018489501 jjt1018489501 于 2015.07.11 22:16 提问

求大神解决VC++等值线插值程序无输出问题

本人C++水平一般,编了一个小程序,调试已过,具体算法就是输进一组由两条等值线数值及坐标构成的数组,然后取三个点找外接圆圆心,再从圆心0-180度内每隔45度引射线与原等值线想交,再找出交点的中点并输出。。。目前测试过数组能正常读入。。。但是输出无结果,求指教,主程序如下
#include
#include
#include
#include
#define shuliang 10000
#define gaodu 1024
#define kuandu 1024
using namespace std;
static int yuanxinx = 0;
static int yuanxiny = 0;
static int jiaodianax = 0;
static int jiaodianay = 0;
static int jiaodianbx = 0;
static int jiaodianby = 0;
static int count1 = 0;
const double pi = 3.1415927;
int juli(int a, int b,int c , int d)//输入两个点的坐标,计算两点间距离
{

return sqrt(pow((a - c), 2) + pow((b - d), 2));
}
bool yuanxin(int ax, int ay, int bx, int by, int cx, int cy)//输入三个点坐标,计算圆心
{
int a, b, c;
bool i=1;
for (int x = 0; x <= gaodu; x++)
{
for (int y = 0; y <= kuandu; y++)
{
a = pow((x - ax), 2) + pow((y - ay), 2);
b = pow((x - bx), 2) + pow((y - by), 2);
c = pow((x - cx), 2) + pow((y - cy), 2);
if (fabs(a-b)<exp(-5)&&fabs(c-b)<exp(-5))
{
yuanxinx = x;
yuanxiny = y;
return i;
break;
}
else i = 0;
return i;
}
}

}
bool zhaojiaodian(int ax, int ay, int a[shuliang][3],int qiyaa,int qiyab)//输入圆心和所有点,寻找所需焦点
{

int d, e, f;
double g1;
double g2;
double h1;
double h2;
int angle;
bool p=1;

for (int n = 0; n <= shuliang; n++)
{

for(int dx = 0;dx<=kuandu;dx++)
{

for(int ex = 0;ex <= kuandu;ex++)
{
for (int dy = 0;dy <= gaodu; dy++)
{

for(int ey =0 ;ey <= gaodu; ey++)
{
if ((a[n][1] == ex && a[n][2] == ey)||(a[n][1] == dx && a[n][2] == dy))
{

d = sqrt(pow(ax-dx,2) + pow(ay-dy,2));
e = sqrt(pow(ax-ex,2) + pow(ay-ey,2));
f = sqrt(pow(dx-ex,2) + pow(dy-ey,2));
if (fabs(e-f-d)<exp(-5))
{
for(int i = 0 ;i <= 4 ; i++)
{
g1 = (ay-dy)/(ax-dx);
g2 = 0;
h1 = atan(g1);
h2 = atan(g2);
angle = fabs(h1 - h2);
if (fabs(angle- i*pi/4)<exp(-5))
{
jiaodianax = dx;
jiaodianay = dy;
jiaodianbx = ex;
jiaodianby = ey;
return p;
break;
}
else p = 0;
return p;
}
}
}
}
}
}
}
}
}
int zhongzhidianx(int ax, int bx)
{
return ax + (bx - ax) / 2;
}
int zhongzhidiany(int ay,int by)
{
return ay + (by - ay) / 2;
}
void main()
{
int a[shuliang][3]; //建立二维数组

ifstream infile("input.txt", ios::in);  //打开已存在的输入文件input.txt
if (!infile)
{
    cout << "输入文件input.txt不存在\n";
    exit(0);
}
ofstream outfile;                              //创建输出文件,若存在则清除该文件内容
outfile.open("output.txt", ios::out);
if (!outfile)
{
    cout << "不能建立输出文件output.txt\n";
    exit(0);
}
char str[2000][20];
int i = 0;
while (!infile.eof())
{
    infile.getline(str[i], 20);
    i++;
}
count1 = i;
int flag = 0;
int value = 0;
for (int k = 0; k <= count1; k++)
{
    flag = 0;
    value = 0;
    for (int l = 0; str[k][l] != '\0'; l++)
    {
        if (str[k][l] != '\t')
        {
            value = value * 10 + (str[k][l] - '0');
        }
        if (str[k][l] == '\t' || str[k][l + 1] == '\0')
        {
            a[k][flag] = value;
            value = 0;
            flag++;
        }
    }

}

//cout< /******************主要算法**************************/
int m =0;
for (int b = 0; b {
if(a[b][0] == a[b+10][0])
{ m++;
if (juli(a[b][1], a[b][2], a[b+5][1], a[b+5][2]) >= 50 && juli(a[b+5][1], a[b+5][2], a[b+10][1], a[b+10][2]) >= 50)
{
if (yuanxin(a[b][1], a[b][2], a[b+5][1], a[b+5][2], a[b+10][1], a[b+10][2]) == 1)
{
if (zhaojiaodian(yuanxinx, yuanxiny, a, a[b][0], a[b][0] + 60) == 1)
{
outfile << a[0][0] + 60 << '\t' << zhongzhidianx(jiaodianax, jiaodianbx) << '\t' << zhongzhidiany(jiaodianay, jiaodianby) << '\n';
}
}
}

    }
}
infile.close();
outfile.close();

}

3个回答

devmiao
devmiao   Ds   Rxr 2015.07.11 22:20
jjt1018489501
jjt1018489501 这个我之前已经看过了。。对我这程序帮助并不大。。现在就把我上面程序改到outfile出结果就可以了。。
2 年多之前 回复
jjt1018489501
jjt1018489501   2015.07.11 22:24

头文件复制上来就不见了。。。。



oyljerry
oyljerry   Ds   Rxr 2015.07.11 23:45

如果你算法数据已经正确,那么输出文件,就是可以把结果组成i一个字符串,然后out一次性写入文件。

Csdn user default icon
上传中...
上传图片
插入图片