Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Math.sqrt(from.x * from.x + from.y * from.y),
Math.PI / 2 - from.yaw,
{units: 'meters'}
);
const toPoint = turf.destination(
[to.longitude, to.latitude, to.altitude],
Math.sqrt(to.x * to.x + to.y * to.y),
Math.PI / 2 - to.yaw,
{units: 'meters'}
);
const distInMeters = turf.distance(fromPoint, toPoint, {units: 'meters'});
// Bearing is degrees from north, positive is clockwise
const bearing = turf.bearing(fromPoint, toPoint);
const bearingInRadians = turf.degreesToRadians(bearing);
const diffZ = to.altitude + to.z - from.altitude - from.z;
return [
distInMeters * Math.sin(bearingInRadians),
distInMeters * Math.cos(bearingInRadians),
diffZ
];
}
/* eslint-enable complexity */
export const getBearing = (coord1, coord2) => {
const point1 = turf.point([coord1.longitude, coord1.latitude]);
const point2 = turf.point([coord2.longitude, coord2.latitude]);
const bearingInDegrees = turf.bearing(point1, point2);
const bearingInRadians = turf.helpers.degreesToRadians(bearingInDegrees);
return {
bearingInDegrees,
bearingInRadians
};
};