RDP1974 40 Posted November 2, 2022 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
FPiette 384 Posted November 2, 2022 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
RDP1974 40 Posted November 2, 2022 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
FPiette 384 Posted November 2, 2022 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
RDP1974 40 Posted November 2, 2022 well, calculate the distance between two points is needed 1 Share this post Link to post
FPiette 384 Posted November 2, 2022 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