개발자 모드/C언어

C언어 두 좌표간 GPS 거리 구하기

인생은직구 2021. 3. 21. 12:18
728x90
#include "stdafx.h"
#include "math.h"
#include <stdio.h>


#define PI 3.141592653589

#define _CRT_SECURE_NO_WARNINGS    // scanf 보안 경고로 인한 컴파일 에러 방지

double ConvertDecimalDegreesToRadians(double deg)
{
	return (deg  * PI / 180);
}



double ConvertRadiansToDecimalDegrees(double rad)
{
	return (rad * 180 / PI);
}




int main(void)
{
	double lon1,lat1;
	double lon2,lat2;


	printf("기준표적 경도/ 위도를 넣으시오\n");
	scanf("%lf %lf",&lon1, &lat1);

	printf("대상표적 경도 / 위도를 넣으시오\n");
	scanf("%lf %lf",&lon2, &lat2);

	printf("%lf %lf\n", lat1, lon1);
	printf("%lf %lf\n", lat2, lon2);


	double theta, dist;

	theta = lon1 - lon2;

	dist = sin(ConvertDecimalDegreesToRadians(lat1)) * sin(ConvertDecimalDegreesToRadians(lat2)) +
		cos(ConvertDecimalDegreesToRadians(lat1)) * cos(ConvertDecimalDegreesToRadians(lat2))*
		cos(ConvertDecimalDegreesToRadians(theta));

	dist = acos(dist);

	dist = ConvertRadiansToDecimalDegrees(dist);

	dist = dist * 60 *1.1515;

	dist = dist *1.609344 * 1000;

	
	printf ("%lf\n",dist);



	return 0;
}

 

728x90