vxl-users

 [Vxl-users] vgl_homg_operators_2d::common_tangents sometimes calculates wrong tangents and different output with compiler-optimization From: Stefan Kuhn - 2005-12-06 07:01:34 ```Hello, using the function common_tangents within the vgl_homg_operators_2d, I came across some strange things. Most of the time it produces the correct tangents, but sometimes the calculated tangents are not correct (dependent on coordinates, radii and angles of the two ellipses). Furthermore there is a difference between the calculated results dependent on the optimization-flag -O0 or -O2 I use to compile my program. The software I use is: VXL-CVS-Version 1.3.0, 2005-10-29 g++ (GCC) 3.3.4 (pre 3.3.5 20040809) SUSE Linux 9.2 I use the following lines of code to demonstrate: #include #include #include #include #include int main() { // 2 ellipses vgl_conic< double > c1(vgl_homg_point_2d< double >(-1, -3), 2, 1.1, 0); vgl_conic< double > c2(vgl_homg_point_2d< double >(-1, 3), 2, 1.1, 0); // tangents vcl_list< vgl_homg_line_2d< double > > tangentList = vgl_homg_operators_2d< double >::common_tangents(c1,c2); // print 2 points of each tangent int i = 0; for( vcl_list< vgl_homg_line_2d< double > >::iterator it = tangentList.begin(); it!=tangentList.end(); ++it) { vgl_homg_line_2d< double > tangent = *it; vgl_homg_point_2d< double > p1, p2; tangent.get_two_points(p1, p2); printf("tangent %d: \n", ++i); printf(" point 1: x:%2.6e, \ty:%2.6e, \tw:%2.6e, \tx/w:%2.6e, \ty/w:%2.6e\n", p1.x(), p1.y(), p1.w(), (p1.x()/p1.w()), (p1.y()/p1.w()) ); printf(" point 2: x:%2.6e, \ty:%2.6e, \tw:%2.6e, \tx/w:%2.6e, \ty/w:%2.6e\n\n", p2.x(), p2.y(), p2.w(), (p2.x()/p2.w()), (p2.y()/p2.w()) ); } return 0; } The output of this code, compiled with 'g++ -O0 -I/usr/local/include/core -I/usr/local/include/core/vcl -I/usr/local/include/ -I/usr/local/include/vcl Main.cpp -lvcl -lvgl -lvnl_algo -lvnl -lnetlib' is (output A): tangent 1: point 1: x:-1.000000e+00, y: 1.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 1.000000e+00 point 2: x:-1.000000e+00, y: 0.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 0.000000e+00 tangent 2: point 1: x:-1.000000e+00, y: 1.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 1.000000e+00 point 2: x:-1.000000e+00, y: 0.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 0.000000e+00 tangent 3: point 1: x: 0.000000e+00, y: 6.043026e+02, w:-4.330278e+02, x/w:-0.000000e+00, y/w:-1.395529e+00 point 2: x: 6.043026e+02, y: 0.000000e+00, w:-6.043026e+02, x/w:-1.000000e+00, y/w:-0.000000e+00 tangent 4: point 1: x: 0.000000e+00, y:-6.043026e+02, w:-4.330278e+02, x/w:-0.000000e+00, y/w: 1.395529e+00 point 2: x:-6.043026e+02, y: 0.000000e+00, w: 6.043026e+02, x/w:-1.000000e+00, y/w: 0.000000e+00 The output of this code, compiled with 'g++ -O2 -I/usr/local/include/core -I/usr/local/include/core/vcl -I/usr/local/include/ -I/usr/local/include/vcl Main.cpp -lvcl -lvgl -lvnl_algo -lvnl -lnetlib' is (output B): tangent 1: point 1: x:-1.017242e-14, y:-0.000000e+00, w:-0.000000e+00, x/w: inf, y/w: nan point 2: x: 0.000000e+00, y:-1.017242e-14, w: 0.000000e+00, x/w: nan, y/w:-inf tangent 2: point 1: x: 0.000000e+00, y:-6.043026e+02, w:-4.330278e+02, x/w:-0.000000e+00, y/w:1.395529e+00 point 2: x:-6.043026e+02, y: 0.000000e+00, w: 6.043026e+02, x/w:-1.000000e+00, y/w:0.000000e+00 tangent 3: point 1: x: 0.000000e+00, y: 6.043026e+02, w:-4.330278e+02, x/w:-0.000000e+00, y/w:-1.395529e+00 point 2: x: 6.043026e+02, y: 0.000000e+00, w:-6.043026e+02, x/w:-1.000000e+00, y/w:-0.000000e+00 tangent 4: point 1: x: 0.000000e+00, y:-5.085508e-15, w: 3.067575e-32, x/w: 0.000000e+00, y/w:-1.657827e+17 point 2: x:-5.085508e-15, y: 0.000000e+00, w:-5.086911e-15, x/w: 9.997242e-01, y/w:-0.000000e+00 * In output A and in output B we get four tangents. That is correct. * In output A the first two tangents are identic. That cannot be correct. * We defined two ellipses lying vertically upon each other with its center on the straight line x=-1. The first two tangents of output A are identic with this straight line, wich means that we have intersection lines and not tangents. * In output B, the component w of the first tangent of the homogenous points are 0. According to the documentation of vgl_homg_line_2d, this means that the line is at infinity. But if correct, how to interpret this result? * I have also examined the parameters of tangent 1 of output B: a:-0.000000e+00, b:0.000000e+00, c:1.017242e-14 * Both outputs in comparison have different results. * Tangents 3 and 4 of output A corresponds to the tangents 2 and 3 of output B and seem to be correct. * Tangent 4 of output B is similar to tangent 1 and 2 of output A. An other interesting thing is: * Minimally rotating the ellipses (0.001) results in four correct tangents for both optimization-flags -O0 and -O2: // 2 ellipses vgl_conic< double > c1(vgl_homg_point_2d< double >(-1, -3), 2, 1.1, 0.001); vgl_conic< double > c2(vgl_homg_point_2d< double >(-1, 3), 2, 1.1, 0.001); and the corresponding output (only for -O0): tangent 1: point 1: x: 0.000000e+00, y: 6.046041e+02, w:-4.334603e+02, x/w:-0.000000e+00, y/w:-1.394831e+00 point 2: x: 6.046041e+02, y: 0.000000e+00, w:-6.046041e+02, x/w:-1.000000e-00, y/w:-0.000000e+00 tangent 2: point 1: x: 0.000000e+00, y:-6.040000e+02, w:-4.325946e+02, x/w:-0.000000e+00, y/w: 1.396226e+00 point 2: x:-6.040000e+02, y: 0.000000e+00, w: 6.040000e+02, x/w:-1.000000e+00, y/w: 0.000000e+00 tangent 3: point 1: x: 0.000000e+00, y: 3.439601e-14, w: 4.207549e-30, x/w: 0.000000e+00, y/w: 8.174832e+15 point 2: x: 3.439601e-14, y: 0.000000e+00, w: 3.438231e-14, x/w: 1.000398e+00, y/w: 0.000000e+00 tangent 4: point 1: x: 0.000000e+00, y: 1.031652e-13, w: 4.207176e-30, x/w: 0.000000e+00, y/w: 2.452125e+16 point 2: x: 1.031652e-13, y: 0.000000e+00, w:-3.438688e-14, x/w:-3.000132e+00, y/w:-0.000000e+00 And: * Using '1' instead of '1.1' for the radius y leads to same outputs for both optimization-flags -O0 and -O2: // 2 ellipses vgl_conic< double > c1(vgl_homg_point_2d< double >(-1, -3), 2, 1, 0); vgl_conic< double > c2(vgl_homg_point_2d< double >(-1, 3), 2, 1, 0); and the corresponding output (for both -O0 and -O2): tangent 1: point 1: x:-1.000000e+00, y: 1.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 1.000000e+00 point 2: x:-1.000000e+00, y: 0.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 0.000000e+00 tangent 2: point 1: x:-1.000000e+00, y: 1.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 1.000000e+00 point 2: x:-1.000000e+00, y: 0.000000e+00, w: 1.000000e+00, x/w:-1.000000e+00, y/w: 0.000000e+00 tangent 3: point 1: x: 0.000000e+00, y: 4.072935e+02, w:-2.880000e+02, x/w:-0.000000e+00, y/w:-1.414214e+00 point 2: x: 4.072935e+02, y: 0.000000e+00, w:-4.072935e+02, x/w:-1.000000e+00, y/w:-0.000000e+00 tangent 4: point 1: x: 0.000000e+00, y:-4.072935e+02, w:-2.880000e+02, x/w:-0.000000e+00, y/w: 1.414214e+00 point 2: x:-4.072935e+02, y: 0.000000e+00, w: 4.072935e+02, x/w:-1.000000e+00, y/w: 0.000000e+00 * But in this case the first two tangents are also not correct. Regards Stefan ```
 [Vxl-users] Re: vgl_homg_operators_2d::common_tangents sometimes calculates wrong tangents and different output with compiler-optimization From: Peter Vanroose - 2005-12-11 20:30:21 ```> sometimes the calculated tangents are not correct > (dependent on coordinates, radii and angles of the ellipses). I guess this will be the case for some "degenerate" cases; the algorithm just does some straightforward calculations (in dual projective space), and should probably check for (and treat separately) those cases. In general, I would expect it to work correctly for at least those cases where the coordinates are not "round" numbers. Because the calculations are done in projective space, sometimes relatively large rounding errors might show up. That explains the differences with different optimisation settings at compilation. > * In output B, the component w of the first tangent of the > homogenous points are 0. This means that the line is at > infinity. How to interpret this result? For example, two parabola will have the line at infinity as a common tangent line. -- Peter. ```