I have a text file that include X,Y,Z coordinates of points. My aim is finding minimum and maximum points and write it another file. For this aim I write a distance function. The points that have maximum distance is minimum and maximum points. here is my code. It works but it does not calculate or write anything.
#include <iostream>
#include<fstream>
#include <math.h>
using namespace std;
double distance (float X1, float Y1, float Z1, float X2, float Y2, float Z2)
{
return sqrt(pow((X2-X1),2)+ pow((Y2-Y1),2)+pow((Z2-Z1),2));
}
int main ()
{
float x1, y1, z1,x2, y2,z2;
ifstream file("D:\\points.txt");
ofstream result ("D:\\result.txt");
double bigdistance=0;
if (file.is_open())
{
while (!file.eof())
{
file>>x1>>y1>>z1;
while (!file.eof())
{
file>>x2>>y2>>z2;
double d= distance (x1,y1,z1,x2,y2,z2);
if (bigdistance<d)
{
bigdistance=d;
result<<x1<<y1<<z1<<endl<<x2<<y2<<z2;
}
}
}
}
else cout <<"cannot open file";
system ("PAUSE");
return 0;
}