4

I am trying to compute angle between two lines (line segment) using ESRI (ArcGIS, JS) in conventional bearing (Eg: N29'E)

I am using Add Toolbar to draw a line segment where point A is a fixed point (already drawn) and when the user is hovering over the map looking for point B, it should display projected angle.

Has anybody tried anything like this before or any idea?

2 Answers 2

5

For anyone needing this:

function computeAngle(pointA, pointB){
                var dLon = (pointB.x - pointA.x) * Math.PI / 180;
                var lat1 = pointA.y * Math.PI / 180;
                var lat2 = pointB.y * Math.PI / 180;
                var y = Math.sin(dLon) * Math.cos(lat2);
                var x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
                var bearing = Math.atan2(y, x)  * 180 / Math.PI;
                bearing = ((bearing + 360) % 360).toFixed(1); //Converting -ve to +ve (0-360)
                if(bearing >= 0 && bearing < 90){
                    return 'N' + (bearing != 0  ? bearing + 'E' : '');
                }
                if(bearing >= 90 && bearing < 180){
                    return (bearing != 90  ? 'S' + (180 - bearing).toFixed(1) : '') + 'E';
                }
                if(bearing >= 180 && bearing < 270){
                    return 'S' + (bearing != 180  ? (bearing - 180).toFixed(1) + 'W' : '');
                }
                if(bearing >= 270){
                    return (bearing != 270  ? 'N' + (360 - bearing).toFixed(1) : '') + 'W';
                }
                return 'N';
}

References:

http://www.movable-type.co.uk/scripts/latlong.html

http://www.mathsteacher.com.au/year7/ch08_angles/07_bear/bearing.htm

4

Bearing Distance To Line (Data Management)

Creates a new feature class containing geodetic line features constructed based on the values in an x-coordinate field, y-coordinate field, bearing field, and distance field of a table.

enter image description here

bearing_units (Optional)

The units of the values in the Bearing Field.

DEGREES —Values in decimal degrees; this is the default.
MILS —Values in mils.
RADS —Values in radians.
GRADS —Values in gradians.

source: http://resources.arcgis.com/en/help/main/10.1/index.html#//0017000000ts000000

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.