Closed acidjazz closed 4 years ago
Hi,
the perpendicular distance is calculated between a point and a great circle which is defined by the line.
It's impossible to determine the perpendicular distance between the point A and the actual line (between the two defining points P1 and P2) in your example.
The reason: there's no way to construct a „right angle“ between A and any point on the line between P1 and P2. The calculated distance is A to X.
I hope the drawing helps to explain it:
I'll update the documentation to clarify things.
@mjaschen very interesting, yes I guess I misunderstood, thanks for the clarification.
I am looking to calculate the distance between a polygon and a point, I thought look through its segments and find the closest one by using this, but now I see where this won't work.
Do you have plans at all to add something like what I'm looking for? It would also be really cool to know where in the segment/line you found to be closest to that point.
Let me know if you want me to close this, or I can close it after you update the documentation
I'd like to add this functionality and will create a separate issue for that.
The documentation is updated to clarify the purpose of the perpendicular distance calculation: https://phpgeo.marcusjaschen.de/Calculations/Perpendicular_Distance.html
I've just noticed that issue #24 covers this already. I'll take a another look.
If you look at this GeoJSON demonstration:
http://geojson.io/#id=gist:acidjazz/8cd03298ddf9bf42168a9ded77577dcf&map=9/29.9216/-94.4000
I have a line drawn near Lake Charles, and a point set near Kingwood, about 120 miles away.
The following code results in 21,989 meters for those coordinates:
This returns
21989.019190836
Now doing a point distance results in 148k-151k, ex:
this results in:
148298.123
151043.798