# Measure North Bearing for a line

Hi,

I am trying to calculate the clockwise angle from north pole to a line. I draw a line on the globe in the following way:

I create a line after clicking once at the start and then at the end point something like:

if(!entity) {
polyline : {
positions : [firstPoint, cartesian],
width : 10.0,
material : new Cesium.PolylineArrowMaterialProperty(new
Cesium.Color(1.0, 0.0, 0.0, 1.0)),
depthFailMaterial : new Cesium.PolylineArrowMaterialProperty(new
Cesium.Color(1.0, 0.0, 0.0, 0.5)),
},
nonPickable: true,
});
} else {
entity.polyline.positions = [firstPoint,endPoint];
}

How can i now measure the north bearing for this line, or any line i draw on the globe like this?

You can calculate bearing between 2 points like this:

``````function calculateBearing(startPoint, endPoint) {
var start = Cesium.Cartographic.fromCartesian(startPoint);
var end = Cesium.Cartographic.fromCartesian(endPoint);

var y = Math.sin(end.longitude - start.longitude) * Math.cos(end.latitude);
var x = Math.cos(start.latitude) * Math.sin(end.latitude) -
Math.sin(start.latitude) * Math.cos(end.latitude) *
Math.cos(end.longitude - start.longitude);

var bearing = Math.atan2(y, x);
return Cesium.Math.toDegrees(bearing);
}
``````
• Regards
1 Like