开发者

Calculate second point knowing the starting point and distance

开发者 https://www.devze.com 2022-12-19 12:39 出处:网络
using a Latitude and Longitude value (Point A), I am trying to calculate another Point B, X meters away bearing 0 radians from point A. Then display the point B Latitude and Longitude values.

using a Latitude and Longitude value (Point A), I am trying to calculate another Point B, X meters away bearing 0 radians from point A. Then display the point B Latitude and Longitude values.

Example (Pseudo code):

PointA_Lat = x.xxxx;
PointA_Lng = x.xxxx;
Distance = 3; //Meters
bearing = 0; //radians

new_PointB = PointA-Distance;

I was able to calculate the distance between two Points but what I want to find is the second开发者_StackOverflow point knowing the distance and bearing.

Preferably in PHP or Javascript.

Thank you


It seems you are measuring distance (R) in meters, and bearing (theta) counterclockwise from due east. And for your purposes (hundereds of meters), plane geometry should be accurate enough. In that case,

dx = R*cos(theta) ; theta measured counterclockwise from due east
dy = R*sin(theta) ; dx, dy same units as R

If theta is measured clockwise from due north (for example, compass bearings), the calculation for dx and dy is slightly different:

dx = R*sin(theta)  ; theta measured clockwise from due north
dy = R*cos(theta)  ; dx, dy same units as R

In either case, the change in degrees longitude and latitude is:

delta_longitude = dx/(111320*cos(latitude))  ; dx, dy in meters
delta_latitude = dy/110540                   ; result in degrees long/lat

The difference between the constants 110540 and 111320 is due to the earth's oblateness (polar and equatorial circumferences are different).

Here's a worked example, using the parameters from a later question of yours:

Given a start location at longitude -87.62788 degrees, latitude 41.88592 degrees, find the coordinates of the point 500 meters northwest from the start location.

If we're measuring angles counterclockwise from due east, "northwest" corresponds to theta=135 degrees. R is 500 meters.

dx = R*cos(theta) 
   = 500 * cos(135 deg) 
   = -353.55 meters

dy = R*sin(theta) 
   = 500 * sin(135 deg) 
   = +353.55 meters

delta_longitude = dx/(111320*cos(latitude)) 
                = -353.55/(111320*cos(41.88592 deg))
                = -.004266 deg (approx -15.36 arcsec)

delta_latitude = dy/110540
               = 353.55/110540
               =  .003198 deg (approx 11.51 arcsec)

Final longitude = start_longitude + delta_longitude
                = -87.62788 - .004266
                = -87.632146

Final latitude = start_latitude + delta_latitude
               = 41.88592 + .003198
               = 41.889118


It might help if you knew that 3600 seconds of arc is 1 degree (lat. or long.), that there are 1852 meters in a nautical mile, and a nautical mile is 1 second of arc. Of course you're depending on the distances being relatively short, otherwise you'd have to use spherical trigonometry.


Here is an updated version using Swift:

let location = CLLocation(latitude: 41.88592 as CLLocationDegrees, longitude: -87.62788 as CLLocationDegrees)

let distanceInMeter : Int = 500
let directionInDegrees : Int = 135

let lat = location.coordinate.latitude
let long = location.coordinate.longitude

let radDirection : CGFloat = Double(directionInDegrees).degreesToRadians

let dx = Double(distanceInMeter) * cos(Double(radDirection)) 
let dy = Double(distanceInMeter) * sin(Double(radDirection))

let radLat : CGFloat = Double(lat).degreesToRadians

let deltaLongitude = dx/(111320 * Double(cos(radLat)))  
let deltaLatitude = dy/110540                   

let endLat = lat + deltaLatitude
let endLong = long + deltaLongitude

Using this extension:

extension Double {
    var degreesToRadians : CGFloat {
        return CGFloat(self) * CGFloat(M_PI) / 180.0
    }
}


dx = sin(bearing)
dy = cos(bearing)
x = center.x + distdx;
y = center.y + dist
dy;

0

精彩评论

暂无评论...
验证码 换一张
取 消