Jump to content

Recommended Posts

hi,

do you know a good source of algotithms for location based purposes?

example calc the distance between two coordinates, etc.

thank you

Share this post


Link to post

If you are talking about  geographic coordinates, look at the haversine formula.

function HaversineDist(
    Lat1 : Extended;   // Latitude  of point 1 in degrees
    Lng1 : Extended;   // Longitude of point 1 in degrees
    Lat2 : Extended;   // Latitude  of point 2 in degrees
    Lng2 : Extended)   // Longitude of point 2 in degrees
    : Extended;        // Distance in meters
var
    Dx, Dy, Dz : Extended;
const
    Diameter = 2 * 6372.8 * 1000;   // Meters
begin
    Lng1    := DegToRad(Lng1 - Lng2);
    Lat1    := DegToRad(Lat1);
    Lat2    := DegToRad(Lat2);

    Dz     := Sin(Lat1) - Sin(Lat2);
    Dx     := Cos(Lng1) * Cos(Lat1) - Cos(Lat2);
    Dy     := Sin(Lng1) * Cos(Lat1);
    Result := ArcSin(Sqrt(sqr(Dx) + Sqr(Dy) + Sqr(Dz)) / 2) * Diameter;
end;

 

Share this post


Link to post

thank you

if I have time will try to implement a general purpose KNN R-Tree algorithm in pascal

 

Share this post


Link to post
22 minutes ago, RDP1974 said:

thank you

if I have time will try to implement a general purpose KNN R-Tree algorithm in pascal

What is the relation with your initial question and my answer ?

Share this post


Link to post

In which space are your points? The formula and code I gave is for computing the distance between two points of given by their geographic coordinates (On a sphere which is the earth in my code). The distance is computed on a great-circle.

The formula for two points located on a plane is different and simpler.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×