## [Vxl-users] Bug: vgl_lineseg_test_point

 [Vxl-users] Bug: vgl_lineseg_test_point From: Dirk Steckhan - 2009-03-10 17:16:31 Hello, there is a bug in the function vgl_lineseg_test_point found in vgl_lineseg_test.h This function will always return false, because someone forgot to take square root to calculate the distances between all three points (pythagoras) // compute distances T d1p = (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1); T d2p = (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2); T d12 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1); should be: // compute distances T d1p = std::sqrt((x3-x1)*(x3-x1) + (y3-y1)*(y3-y1)); T d2p = std::sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2)); T d12 = std::sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); Regards, Dirk Steckhan VXL-Version: 1.12.0 Compiler: VS9 SP1 OS WinXP

### Thread view

 [Vxl-users] Bug: vgl_lineseg_test_point From: Dirk Steckhan - 2009-03-10 17:16:31 Hello, there is a bug in the function vgl_lineseg_test_point found in vgl_lineseg_test.h This function will always return false, because someone forgot to take square root to calculate the distances between all three points (pythagoras) // compute distances T d1p = (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1); T d2p = (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2); T d12 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1); should be: // compute distances T d1p = std::sqrt((x3-x1)*(x3-x1) + (y3-y1)*(y3-y1)); T d2p = std::sqrt((x3-x2)*(x3-x2) + (y3-y2)*(y3-y2)); T d12 = std::sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); Regards, Dirk Steckhan VXL-Version: 1.12.0 Compiler: VS9 SP1 OS WinXP
 Re: [Vxl-users] Bug: vgl_lineseg_test_point From: Peter Vanroose - 2009-03-10 20:38:21 > there is a bug in the function vgl_lineseg_test_point found > in vgl_lineseg_test.h > This function will always return false, because someone > forgot to take square root to calculate the distances Thanks! I've applied the fix. (Actually, I took the occasion to also clean up a little bit. See new implementation below.) I'll also verify whether there is a test for this function in core/vgl/tests and possibly add one. Then I'll put it in CVS from where it should make it to VXL 1.13. -- Peter. template bool vgl_lineseg_test_point(vgl_point_2d const& p, vgl_line_segment_2d const& lseg) vgl_point_2d p1 = lseg.point1(), p2 = lseg.point2(); T x1 = p1.x(), y1 = p1.y(), x2 = p2.x(), y2 = p2.y(), xp = p.x(), yp = p.y(); // compute squared distances T d1p = (xp-x1)*(xp-x1) + (yp-y1)*(yp-y1); T d2p = (xp-x2)*(xp-x2) + (yp-y2)*(yp-y2); T d12 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1); double diff = vcl_sqrt(d1p) + vcl_sqrt(d2p) - vcl_sqrt(d12); // diff is always >= 0 (triangle inequality) return diff <= vgl_tolerance::position; ======================================================================= __________________________________________________________ Ta semester! - sök efter resor hos Kelkoo. Jämför pris på flygbiljetter och hotellrum här: http://www.kelkoo.se/c-169901-resor-biljetter.html?partnerId=96914052

## Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks