Difference between revisions of "AppInventor: Menghitung Jarak dan Arah dari GPS"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
Onnowpurbo (talk | contribs)  | 
				Onnowpurbo (talk | contribs)   | 
				||
| Line 51: | Line 51: | ||
  Y = cos θa * sin θb – sin θa * cos θb * cos ∆L  |   Y = cos θa * sin θb – sin θa * cos θb * cos ∆L  | ||
| + | ==Menghitung Arah==  | ||
| + | |||
| + | Formula:  | ||
| + | |||
| + |  θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )  | ||
| + | |||
| + | JavaScript:  | ||
| + | (all angles  | ||
| + | in radians)  | ||
| + | |||
| + |  var y = Math.sin(λ2-λ1) * Math.cos(φ2);  | ||
| + |  var x = Math.cos(φ1)*Math.sin(φ2) -  | ||
| + |          Math.sin(φ1)*Math.cos(φ2)*Math.cos(λ2-λ1);  | ||
| + |  var brng = Math.atan2(y, x).toDegrees();  | ||
==Arah Kiblat==  | ==Arah Kiblat==  | ||
Latest revision as of 05:42, 11 October 2015
Sumber: https://sites.google.com/site/appinventor/distance-based-on-lat-long
Menghitung Jarak
Jarak:
distance = sqrt(x^2 + y^2)
Dimana:
x = 69.1 * (lat2 - lat1) y = 69.1 * (lon2 - lon1) * cos(lat1/57.3)
Menghitung Jarak dengan 'Haversine' Formula
Haversine formula:
	a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
       c = 2 ⋅ atan2( √a, √(1−a) )
       d = R ⋅ c
where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km); note that angles need to be in radians to pass to trig functions!
JavaScript:
var R = 6371000; // metres
var φ1 = lat1.toRadians();
var φ2 = lat2.toRadians();
var Δφ = (lat2-lat1).toRadians();
var Δλ = (lon2-lon1).toRadians();
var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
        Math.cos(φ1) * Math.cos(φ2) *
        Math.sin(Δλ/2) * Math.sin(Δλ/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
Ref: http://www.movable-type.co.uk/scripts/latlong.html
Menghitung Arah
Arah:
β = atan2(X,Y),
Dimana
X = cos θb * sin ∆L Y = cos θa * sin θb – sin θa * cos θb * cos ∆L
Menghitung Arah
Formula:
θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
JavaScript: (all angles in radians)
var y = Math.sin(λ2-λ1) * Math.cos(φ2);
var x = Math.cos(φ1)*Math.sin(φ2) -
        Math.sin(φ1)*Math.cos(φ2)*Math.cos(λ2-λ1);
var brng = Math.atan2(y, x).toDegrees();
Arah Kiblat
PI = 3.1415926535; phiK = 21.422507*PI/180.0; lambdaK = 39.826329*PI/180.0; phi = lat*PI/180.0; lambda = lon*PI/180.0; psi = 180.0/PI*atan2(sin(lambdaK-lambda), cos(phi)*tan(phiK)-sin(phi)*cos(lambdaK-lambda)); return Math.round(psi);
Ref: http://www.islamicsoftware.org/qibla/qibla.html