RE: [mapguide-users] Calculating a Euclidean Distance in Javascript
Hmmm...something's not lining up right. Here are my test values: Start Point x1 = 782968.222103 y1 = 1774880.116909 End Point x2 = 783044.338 y2 = 1774867.244367 I used this formula in php: $distance = sqrt(pow($x1 - $x2,2.0) + pow($y1 = $y2,2.0)) This gave me a value of 77.19671051057 $srsMap-MeasureEuclideanDistance($x1,$y1,$x2,$y2) gave me 23.529604265472 It looks like I'm using the same formula, but I am getting a dramatically different result. -- View this message in context: http://www.nabble.com/Calculating-a-Euclidean-Distance-in-Javascript-tp17348713p17404134.html Sent from the MapGuide Users mailing list archive at Nabble.com. ___ mapguide-users mailing list mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users
Re: [mapguide-users] Calculating a Euclidean Distance in Javascript
It's either a pretty interesting coincidence that 23.529 / 77.196 = 0.3048, or else it's a units problem you've got (feet vs meters). 1 foot = 0.3048m. Andrew nclayton wrote: Hmmm...something's not lining up right. Here are my test values: Start Point x1 = 782968.222103 y1 = 1774880.116909 End Point x2 = 783044.338 y2 = 1774867.244367 I used this formula in php: $distance = sqrt(pow($x1 - $x2,2.0) + pow($y1 = $y2,2.0)) This gave me a value of 77.19671051057 $srsMap-MeasureEuclideanDistance($x1,$y1,$x2,$y2) gave me 23.529604265472 It looks like I'm using the same formula, but I am getting a dramatically different result. -- Andrew DeMerchant Computer Technologist ph.1-877-2GEMTEC x.163 fax 506-453-9470 GEMTECLimited 191 Doak Road Fredericton, NB, Canada E3C 2E6 ___ mapguide-users mailing list mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users
Re: [mapguide-users] Calculating a Euclidean Distance in Javascript
I think you just solved the problem...I am using US Survey Feet as my coordinate system. So if this is truely the case and not a coincidence, then I don't have to recalculate to feet because it's already there. I'll try that and see what I get. Thanks for the input! andrew.demerchant wrote: It's either a pretty interesting coincidence that 23.529 / 77.196 = 0.3048, or else it's a units problem you've got (feet vs meters). 1 foot = 0.3048m. Andrew nclayton wrote: Hmmm...something's not lining up right. Here are my test values: Start Point x1 = 782968.222103 y1 = 1774880.116909 End Point x2 = 783044.338 y2 = 1774867.244367 I used this formula in php: $distance = sqrt(pow($x1 - $x2,2.0) + pow($y1 = $y2,2.0)) This gave me a value of 77.19671051057 $srsMap-MeasureEuclideanDistance($x1,$y1,$x2,$y2) gave me 23.529604265472 It looks like I'm using the same formula, but I am getting a dramatically different result. -- *Andrew DeMerchant* *Computer Technologist* ph.1-877-2GEMTEC x.163 fax 506-453-9470 /GEMTEC Limited http://www.gemtec.ca /191 Doak Road Fredericton, NB, Canada E3C 2E6 ___ mapguide-users mailing list mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users -- View this message in context: http://www.nabble.com/Calculating-a-Euclidean-Distance-in-Javascript-tp17348713p17404339.html Sent from the MapGuide Users mailing list archive at Nabble.com. ___ mapguide-users mailing list mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users
Re: [mapguide-users] Calculating a Euclidean Distance in Javascript
Things look good. Thank you all for your input. So the final formula is: Math + Mapping me But I am now able to reliably place measure segment length out while it is being drawn (I am using the wz_jsgraphics library to draw a rubber-band between the click start point and the mouse cursor). -- View this message in context: http://www.nabble.com/Calculating-a-Euclidean-Distance-in-Javascript-tp17348713p17404960.html Sent from the MapGuide Users mailing list archive at Nabble.com. ___ mapguide-users mailing list mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users
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(LMgCoordinateSystem.MeasureEuclideanDistance) return distance; } Hope this helps. Bruce -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of nclayton Sent: Tuesday, May 20, 2008 1:27 PM To: mapguide-users@lists.osgeo.org 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 mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users ___ mapguide-users mailing list mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users