1

For example: Lets say, we have some kind of straight wall on the earth map, and we know lat/lon coordinates of it's start and finish points:

wall.start.lat, wall.start.lon
wall.end.lat, wall.end.lon

And also we have some kind of object aside:

object.lat
object.lon

What i need is to find the closest point of the wall to this object if i will walk from that object to the wall on the surface.

It's pretty easy to solve on the plane, but i've stuck with sphere.

CrazyWu
  • 647
  • 2
  • 8
  • 19
  • The distance between two points in a sphere, measured along the arc on the surface of the sphere, is called "Great-circle distance. See [Wikipedia](https://en.wikipedia.org/wiki/Great-circle_distance). For the distance from a point perpendicular to an arc see [my answer](https://stackoverflow.com/a/53147219/3871028) – Ripi2 Apr 10 '19 at 15:42
  • @Ripi2 thanks. it might help, but in the end i'm trying to get the coordinates of closest point, not a distance – CrazyWu Apr 10 '19 at 17:05
  • For closest point use the great-circle method for both wall ends and choose the smaller distance. – Ripi2 Apr 10 '19 at 20:06

2 Answers2

1

You can use Cross-track distance section at this latlong page

 I’ve sometimes been asked about distance of a point from a great-circle path (sometimes called cross track error).

Formula:    dxt = asin( sin(δ13) ⋅ sin(θ13−θ12) ) ⋅ R
where   δ13 is (angular) distance from start point to third point
θ13 is (initial) bearing from start point to third point
θ12 is (initial) bearing from start point to end point
R is the earth’s radius
JavaScript: 
var δ13 = d13 / R;
var dXt = Math.asin(Math.sin(δ13)*Math.sin(θ13-θ12)) * R;
Here, the great-circle path is identified by a start point and an end point – depending on what initial data you’re working from, you can use the formulas above to obtain the relevant distance and bearings. The sign of dxt tells you which side of the path the third point is on.

The along-track distance, from the start point to the closest point on the path to the third point, is

Formula:    dat = acos( cos(δ13) / cos(δxt) ) ⋅ R
where   δ13 is (angular) distance from start point to third point
δxt is (angular) cross-track distance
R is the earth’s radius
JavaScript: 
var δ13 = d13 / R;
var dAt = Math.acos(Math.cos(δ13)/Math.cos(dXt/R)) * R;

and the apply Destination point given distance and bearing from start point approach to get point coordinates

MBo
  • 77,366
  • 5
  • 53
  • 86
0

I would:

  1. Assuming a unit sphere, calculate the vectors from the center to the segment end points
  2. Cross-product to get a normal to the plane that contains the segment
  3. Normalize length and dot-product with the object point to get its distance from the plane
  4. asin() to convert that to a distance along the surface to the segment's great circle path
  5. multiply by the real radius to get the appropriate units

You'll also need the distances between the object point and the segment end points in case they turn out to be closer.

Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87