Python
두 gps 지점으로 방위각 구하기
지니
2022. 1. 24. 15:18
반응형
php 로 짜다가 파이썬으로 바꿔야 해서 구글링 시작
사실 구글링 하다보면 나오긴 하는데... 각도가 2~3도씩이나 차이가 나서 쓸수가 없었다.
C언어로는 많아서 그냥 파이썬에서 C를 불러다 쓸까~ㅎㅎ 하다가 아우~ 이것도 귀찮아서 파이썬으로 짰다 그냥
https://www.omnicalculator.com/other/azimuth
Azimuth Calculator
If you want to give a location of a point relative to your current position, you need to provide two values: the azimuth and the distance. If Earth was flat, the latter would simply by the straight-line distance between two points. As Earth is a sphere (or
www.omnicalculator.com

두 지점의 방위각이 347.4 도 라고 한다.
이제 파이썬 함수를 이용해 구해보자.
1. 준비하기
두가지를 호로록 설치해준다.
pip install numpy #numpy 설치
pip install math #math 설치
2. 방위각 함수
나중에 쓸땐 print 지우고 깔끔하게 쓰심 됩니다.
def Azimuth(lat1, lng1, lat2, lng2):
Lat1 = math.radians(lat1)
print(Lat1)
Lat2 = math.radians(lat2)
print(Lat2)
Lng1 = math.radians(lng1)
print(Lng1)
Lng2 = math.radians(lng2)
print(Lng2)
y = math.sin(Lng2-Lng1)*math.cos(Lat2)
print(y)
x = math.cos(Lat1)*math.sin(Lat2)-math.sin(Lat1)*math.cos(Lat2)*math.cos(Lng2-Lng1)
print(x)
z = math.atan2(y, x)
a = numpy.rad2deg(z)
print(a)
if(a < 0):
a = 180+(180+a)
return a
3. 사용하기
math 와 , numpy import 해서 써주면 끝!
import math
import numpy
Angle = Azimuth( 37.02828302166191 , 126.85734872883606 , 37.64102883333334 , 126.68457433333333 )
Angle = Azimuth( lat1 , lng1 , lat2 , lng2 )
4. 결과

똑같이 347.4도 나왔다.
끝!
반응형