I have some code that uses latitude and longitude as input values to calculate a second point based on bearing and distance. Haven't used this in quite a while. I'm not sure how much efficiency you need, you would have handle any additional coordinate conversions:
function bearingDistance(lat, lon, radius, bearing){
const lat1Rads = toRad(lat);
const lon1Rads = toRad(lon);
const R_KM = 6371; // radius in KM
const d = radius/R_KM; //angular distance on earth's surface
const bearingRads = toRad(bearing);
const lat2Rads = Math.asin(
Math.sin(lat1Rads) * Math.cos(d) + Math.cos(lat1Rads) * Math.sin(d) * Math.cos(bearingRads)
);
const lon2Rads = lon1Rads + Math.atan2(
Math.sin(bearingRads) * Math.sin(d) * Math.cos(lat1Rads),
Math.cos(d) - Math.sin(lat1Rads) * Math.sin(lat2Rads)
);
return {
latitude: toDeg(lat2Rads),
longitude: toDeg(lon2Rads)
}
}
function toRad(degrees){
return degrees * Math.PI / 180;
}
function toDeg(radians){
return radians * 180 / Math.PI;
}