Рет қаралды 1,147
#아두이노 #Arduino #GPS #방위 #거리
예제 코드
float bearing(float st_lat, float st_lon, float des_lat, float des_lon){
float d_lat = des_lat - st_lat;
float d_lat_meter = d_lat*60*1852;
float d_lon = des_lon - st_lon;
float mid_lat = (st_lat + des_lat)/2;
float d_lon_meter = d_lon*cos(mid_lat/180*3.141592)*60*1852;
float distance_meter = sqrt(d_lat_meter*d_lat_meter + d_lon_meter*d_lon_meter);
float bearing = acos(d_lat_meter/distance_meter)*180/3.141592;
if(d_lon [[[왼쪽이 작음을 나타내는 꺽쇄]]] 0) bearing = 360 - bearing;
return bearing;
}
float distance(float st_lat, float st_lon, float des_lat, float des_lon){
float d_lat = des_lat - st_lat;
float d_lat_meter = d_lat*60*1852;
float d_lon = des_lon - st_lon;
float mid_lat = (st_lat + des_lat)/2;
float d_lon_meter = d_lon*cos(mid_lat/180*3.141592)*60*1852;
return sqrt(d_lat_meter*d_lat_meter + d_lon_meter*d_lon_meter);
}
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.print("방위: ");
Serial.println(bearing(35.20, 129.50, 35.30, 129.60),6);
Serial.print("거리: ");
Serial.println(distance(35.20, 129.50, 35.30, 129.60),6);
delay(000);
}