precision - CGAL: Point on the line? -
i've encountered strange thing in cgal. have line , point supposed on line. code
typedef cgal::exact_predicates_exact_constructions_kernel kernel; int main( ) { cgal::line_2<kernel> l(0.2, 1.0, -1.4); std::cout << l.has_on(cgal::point_2<kernel>(-3.0, 2.0)) << std::endl; std::cout << l.y_at_x(-3.0).exact() << std::endl; return 0; }
produces output:
0 36028797018963967/18014398509481984
ok, maybe exact_predicates_exact_constructions_kernel
not enough... (why?)
i tried use kernel defined cgal::quotient
instead:
typedef cgal::quotient<cgal::mp_float> nt; typedef cgal::cartesian<nt> kernel; int main( ) { cgal::line_2<kernel> l(0.2, 1.0, -1.4); std::cout << l.has_on(cgal::point_2<kernel>(-3.0, 2.0)) << std::endl; std::cout << l.y_at_x(-3.0) << std::endl; return 0; }
and result more mysterious me:
0 2/1
am missing or bug?
when construct line 0.2, 2 conversions happen. string "0.2" converted double compiler. then, double converted number type of kernel (an exact rational in case).
the problem conversion of 0.2 double not exact, since 0.2 rational not representable floating-point value, so, inexactness introduced. cgal cannot this.
if need represent 0.2 exactly, need use :
cgal::line_2<kernel> l(nt(2)/nt(10), 1.0, nt(-14)/nt(10));
alternatively, scale problem power of ten coordinates becomes integers.
it possible rational number types have ability construct directly string representing rational number without rounding, don't think cgal::quotient<mp_float>
can.
Comments
Post a Comment