It would be informative to know the values for x1, x2, y1, and y2. If the 
distance value is small compared to the absolute values of the coordinates, 
there could be "catastrophic cancellation" in both of these formulae, due to a 
multiplication happening after a subtraction of nearly equal numbers, causing 
massive loss of floating point precision.


Traian



> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:mapguide-users-
> [EMAIL PROTECTED] On Behalf Of Bruce Dechant
> Sent: Wednesday, May 21, 2008 1:21 PM
> To: MapGuide Users Mail List
> Subject: RE: [mapguide-users] Calculating a Euclidean Distance in
> Javascript
>
> This is the exact code that is being executed by the
> MeasureEuclideanDistance API:
>
> double CCoordinateSystem::MeasureEuclideanDistance(double x1, double
> y1, double x2, double y2)
> {
>     double distance = 0.0;
>
>     MG_TRY()
>     distance = ::sqrt(::pow(x1 - x2, 2.0) + ::pow(y1 - y2, 2.0));
>     MG_CATCH_AND_THROW(L"MgCoordinateSystem.MeasureEuclideanDistance")
>
>     return distance;
> }
>
> Hope this helps.
>
> Bruce
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:mapguide-users-
> [EMAIL PROTECTED] On Behalf Of nclayton
> Sent: Tuesday, May 20, 2008 1:27 PM
> To: [email protected]
> Subject: [mapguide-users] Calculating a Euclidean Distance in
> Javascript
>
>
> I'm trying to reproduce the function being called in php to measure the
> distance between the two points of the measure tool in javascript so
> that I
> can display the current distance while a user is picking a second point
> on
> the map. So far the formula I have tried is not producing the same
> result as
> the result of
> $srsMap->MeasureEuclideanDistance($x1,$y1,$x2,$y2) in measure.php
>
> the formula I am trying is:
> distance = sqrt(abs(x2 - x1)^2 + abs(y2-y1)^2)
>
> then to convert to miles:
> miles = distance * 0.000621371192
>
> Thanks in advance for any input.
> --
> View this message in context: http://www.nabble.com/Calculating-a-
> Euclidean-Distance-in-Javascript-tp17348713p17348713.html
> Sent from the MapGuide Users mailing list archive at Nabble.com.
>
> _______________________________________________
> mapguide-users mailing list
> [email protected]
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
> _______________________________________________
> mapguide-users mailing list
> [email protected]
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
_______________________________________________
mapguide-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to