mjaschen / phpgeo

Simple Yet Powerful Geo Library for PHP
https://phpgeo.marcusjaschen.de
MIT License
1.56k stars 195 forks source link

Calculate cardinal direction distances between two coordinates #73

Closed LeoVie closed 3 years ago

LeoVie commented 4 years ago

Given you have two Coordinates:

you'd like to know the shortest possible right angle to reach the Point2 from Point1 grafik

This would be possible by determining the point in the NorthWest corner (Point3) and calculate the distances Point1<->Point3 and Point2<->Point3.

As the sortest possible distances should be calculated, there has to be a check before: If Point1 is in NorthWest of Point2, the shortest directions are to go south and east.

Point1 in reference to Point2 Directions
North South
East West
South North
West East
NorthWest South, East
NorthEast South, West
SouthWest North, East
SouthEast North, West

The only real new logic would be this determination. The determining of Point3 could be done via the class Bounds, the calculation of the distances via the class Coordinate.

What do you think about this feature? If something is unclear, please ask me. :)

mjaschen commented 4 years ago

That sounds like it's a useful feature which should be relatively easy to implement :-)

LeoVie commented 4 years ago

Nice, I'll implement it in the next days.