Search code examples
javascriptgisarcgis-js-api

Get new point coordinate by current Point coordinate, angle and distance in arcgis js api 4.x


I want to get coordinate (x,y) of a point B based on coordinate of point A and distance from the point A and an angle using Arcgis js API 4.x .

For example : i have point A in (a,b) the distance between A and B is 500m and the angle is 20°, how can i get (x,y) of B.

enter image description here


Solution

  • i fount the equation here, i implemented it and it works perfectly.

    this is my simple :

        const R = 6371e3; //rayon of the erth
        let lat1 = 36.7538 * Math.PI / 180; // latitude in rad
        let long1 = 3.0588 * Math.PI / 180; // longiture in rad
        let d = 5000; //distance between the two points
        let angle = (90-20)*Math.PI/180; // the angle between the 2 points in rad (20°)
        const sigma = d / R;
        const delLat = sigma * Math.cos(angle);
        let lat2 = (lat1 + delLat) * 180 / Math.PI;//latitude of the destination point
        const del = Math.log(Math.tan(lat2 / 2 + Math.PI / 4) / Math.tan(lat1 / 2 + Math.PI / 4));
        // const q = Math.abs(del) > 10e-12 ? delLat / del : Math.cos(lat1); 
        const q = Math.cos(lat1)
        
        const delLong = sigma * Math.sin(angle) / q;
        let long2 = (long1 + delLong) * 180 / Math.PI; //longitude of the destination point