mirror of https://github.com/CGAL/cgal
Improve the examples which illustrate problems with double
This commit is contained in:
parent
120890cacc
commit
a801f9e185
|
|
@ -43,7 +43,7 @@ precision floating point numbers for the %Cartesian coordinates of the point.
|
||||||
|
|
||||||
Besides the types we see \em predicates like the orientation test for
|
Besides the types we see \em predicates like the orientation test for
|
||||||
three points, and \em constructions like the distance and midpoint
|
three points, and \em constructions like the distance and midpoint
|
||||||
computation. A predicate has a discrete set of possible answers,
|
computation. A predicate has a discrete set of possible results,
|
||||||
whereas a construction produces either a number, or another
|
whereas a construction produces either a number, or another
|
||||||
geometric entity.
|
geometric entity.
|
||||||
|
|
||||||
|
|
@ -83,15 +83,40 @@ extract constructions.
|
||||||
|
|
||||||
\cgalExample{Kernel_23/exact.cpp}
|
\cgalExample{Kernel_23/exact.cpp}
|
||||||
|
|
||||||
|
Here comes the output and you may still be surprised.
|
||||||
|
|
||||||
|
\verbatim
|
||||||
|
not collinear
|
||||||
|
collinear
|
||||||
|
collinear
|
||||||
|
\endverbatim
|
||||||
|
|
||||||
|
In the first block the points are still not collinear,
|
||||||
|
for the simple reason that the coordinates you see as text
|
||||||
|
get turned into floating point numbers. When they are then
|
||||||
|
turned into arbitrary precision rationals, they exactly
|
||||||
|
represent the floating point number, but not the text.
|
||||||
|
|
||||||
|
This is different in the second block, which corresponds
|
||||||
|
to reading numbers from a file. The arbitrary precision
|
||||||
|
rationals are then directly constructed from a string
|
||||||
|
so that they represent exactly the text.
|
||||||
|
|
||||||
|
In the third block you see that constructions as
|
||||||
|
midpoint constructions are exact, just as the name
|
||||||
|
of the kernel type suggests.
|
||||||
|
|
||||||
|
|
||||||
In many cases you will have floating point numbers that are "exact",
|
In many cases you will have floating point numbers that are "exact",
|
||||||
in the sense that they were computed by some application or obtained
|
in the sense that they were computed by some application or obtained
|
||||||
from a sensor. They are not the string "0.1" or computed on the
|
from a sensor. They are not the string "0.1" or computed on the
|
||||||
fly as "1.0/10.0", but a full precision floating point number.
|
fly as "1.0/10.0", but a full precision floating point number.
|
||||||
If they are input to an algorithm that makes no constructions
|
If they are input to an algorithm that makes no constructions
|
||||||
you can use a kernel that provides exact predicates, but inexact
|
you can use a kernel that provides exact predicates, but inexact
|
||||||
constructions. An example for that is the convex hull algorithm.
|
constructions. An example for that is the convex hull algorithm
|
||||||
The output is a subset of the input, and all the algorithm
|
which we will see in the next section.
|
||||||
does is to compare coordinates and perform orientation tests.
|
The output is a subset of the input, and the algorithm
|
||||||
|
only compares coordinates and performs orientation tests.
|
||||||
|
|
||||||
At a first glance the kernel doing exact predicates and constructions
|
At a first glance the kernel doing exact predicates and constructions
|
||||||
seems to be the perfect choice, but performance requirements
|
seems to be the perfect choice, but performance requirements
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,27 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||||
|
|
||||||
|
|
||||||
typedef Kernel::Point_2 Point_2;
|
typedef Kernel::Point_2 Point_2;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
Point_2 p(0, 0.3), q, r(2, 0.9);
|
||||||
{
|
{
|
||||||
Point_2 p(0, 0.3), q(1, 0.6), r(2, 0.9);
|
q = Point_2(1, 0.6);
|
||||||
Point_2 m = CGAL::midpoint(p,r);
|
std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not collinear\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::istringstream input("0 0.3 1 0.6 2 0.9");
|
||||||
|
input >> p >> q >> r;
|
||||||
|
std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not collinear\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
q = CGAL::midpoint(p,r);
|
||||||
std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not collinear\n");
|
std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not collinear\n");
|
||||||
std::cout << (CGAL::collinear(p,m,r) ? "collinear\n" : "not collinear\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue