Select to view content in your preferred language

Get new point coordinate by current Point coordinate, angle and distance

2570
6
Jump to solution
07-20-2021 07:57 AM
mohameantar
New Contributor

Hello all,

i want to create new point to be away by specific angle and distance from existing point .

i checked geometryEngine.offset but its working only for polyline or polygon not working for points also i need to control the angle so i create the new point up or down not only right and left.

Thank you all

 

 

0 Kudos
1 Solution

Accepted Solutions
AndyGup
Esri Regular Contributor

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;
        }

 

View solution in original post

6 Replies
AndyGup
Esri Regular Contributor

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;
        }

 

JayakumarPD
Frequent Contributor

Hi sir, we are using the same code as given but getting the point at a wrong distance, kindly help us how to get the new point at given distance.  

For lat- lattittue 

       log- logitude

       radius- distance we are passing(line distance)

       bearing- angle

if we enter 200 mt distance, the line length will be 652 mt.  How to get the new point at the exact line distance, which we are providing.  The screen shot provided for reference.

0 Kudos
AndyGup
Esri Regular Contributor
0 Kudos
JayakumarPD
Frequent Contributor

thank you sir, 

0 Kudos
mohameantar
New Contributor

its working, thank you exactly what i want 😀

0 Kudos
JohnGrayson
Esri Regular Contributor

You can also try the pointFromDistance() method: Geodetically computes the location at a defined distance and direction from a known location.

0 Kudos