# [Koleksi Kode Sumber] (9) : Menghitung jarak absolut dan relatif antara titik-titik berbeda

## Menghitung jarak absolut dan relatif antara titik-titik berbeda

```/* this program finds the absolute and relative distance between the
different points. the input to the program is the output of the
program Extract.c */

#include<stdio.h>
#include <math.h>
#define PI 3.141592654
//DIstance calculations
void main()
{
long double l1,l2,g1,g2,lat,lon;
float data;
long double dist_m,dist_m1;
int i;
FILE *abs_distance_f;
FILE *rel_distance_f;
FILE *raw_data_f;
long double get_distance(long double,long double, long double,long double);
clrscr();
raw_data_f=fopen("D:\\sapna\\output1.txt","r");
abs_distance_f=fopen("D:\\sapna\\abs_distance.txt","w");
rel_distance_f=fopen("D:\\sapna\\rel_distance.txt","w");
fscanf(raw_data_f,"%f",&data);
// printf("%f ",data);
fscanf(raw_data_f,"%f",&data);
// printf("%f ",data);
l1=data; // fixing initial latitude
lat=data;
fscanf(raw_data_f,"%f",&data);
// printf("%f ",data);
g1=data; // fixing initial longitude
lon=data;
// while(data!=EOF)
// for ( i=0;i<3181;i++)
for ( i=0;i<2472;i++)
// for(i=0;i<100;i++)
{
fscanf(raw_data_f,"%f",&data);
fscanf(raw_data_f,"%f",&data);
l2=data;
fscanf(raw_data_f,"%f",&data);
g2=data;
dist_m=get_distance(lat,lon,l2,g2);
fprintf(abs_distance_f,"%Lf \n",dist_m);
dist_m1=get_distance(l1,g1,l2,g2);
// fprintf(rel_distance_f,"%f ,%f ,%f ,%f\n",l1,g1,l2,g2);
fprintf(rel_distance_f,"%Lf \n",dist_m1);
l1=l2;
g1=g2;
}
}
long double get_distance(long double L1, long double G1,long double L2,long double G2)
{
long double DG;
long double temp,d_temp,temp1,distance_km;
DG=G2-G1;
// printf("DG=%f\t",DG);
// calcutating the distance between two points defined interms of latitude and longitude.
if (temp> 1.0)
{
temp1=temp-1;
if (temp1<0.00001)
{
temp=1.0;
}
else
printf(" the error in acos computation");
}
// printf("temp=%.10Lf\t",temp);
d_temp=acosl(temp)*(temp/PI)*180;
// printf("d_temp=%.10Lf\t",d_temp);
distance_km=d_temp*60*1.852;
// printf("distance=%.10Lf \n",distance_km);
return(distance_km*1000);
}```

Sumber :
Centre for Aerospace Systems Design and Engineering, India Institute of Technology Bombay (IITB)