2016-09-12 4 views
0

세 개의 지오 로케이션 사이의 각도를 계산해야합니다.이 중 두 개는 항상 같고 한 개만 변경됩니다 (예 : 사용자가 걷는 경우).세 개의 지오메트리 사이의 각도

enter image description here

먼저 포인트 사용자의 시작 위치이다. 두 번째 점은 사용자의 현재 위치이므로 첫 번째 점은 두 번째 점과 같습니다. 첫 번째 점과 고정 점은 항상 같습니다. 각 지점마다 위도와 경도가 있습니다.

는 I이 화학식 사용하려고 :

double angle1 = Math.atan2(startingLocation.getLongitude() - destinationLocation.getLongitude(), startingLocation.getLatitude() - destinationLocation.getLatitude()); 
double angle2 = Math.atan2(currentLocation.getLongitude() - destinationLocation.getLongitude(), currentLocation.getLatitude() - destinationLocation.getLatitude()); 

return Math.toDegrees(angle1 - angle2); 

을하지만, 예를 들어도 제외한 제 점 == 번째 포인트 I 0이어야하지만 날 (176)도 같은 이상한 결과를 제공 할 때. 문제가 어디에 있습니까?

+0

@ Sabish.M이 주제의 그림 만 빌 렸습니다. – TomTom

답변

0

각도가 기능을 수행하여 계산 될 수를 사용하여 소스

public static double angleBetween2Lines(Line2D line1, Line2D line2) 
{ 
    double angle1 = Math.atan2(line1.getY1() - line1.getY2(), 
          line1.getX1() - line1.getX2()); 
    double angle2 = Math.atan2(line2.getY1() - line2.getY2(), 
          line2.getX1() - line2.getX2()); 
    return angle1-angle2; 
} 

: 엔드 포인트는 (x2,y2) 및 고정

출발점이 (x1,y1) 경우입니다 Calculating the angle between two lines without having to calculate the slope? (Java) 포인트가 (x3,y3)이면

을 사용해야합니다.3210
double angle1 = Math.atan2(y3-y1,x3-x1); 
double angle2 = Math.atan2(y3-y2,x3-x2); 
double result = angle1-angle2; 
+0

You'r 두 번째 해결 방법이 정확합니다. 고맙습니다! – TomTom

+0

@TomTom : 당신은 환영합니다 :) –

0

두 줄 사이에이

double theta = 180.0/Math.PI * Math.atan2(x1 - x2, y1 - y2); 
+0

이 세 번째 Geolocation은 어떻습니까? – TomTom

관련 문제