-
Notifications
You must be signed in to change notification settings - Fork 147
Exact
The geometric algorithms in Geogram, such as 2D triangulations, 3D triangulations, mesh intersection and mesh CSG depend on on more "elementary questions", such as whether a point is above or below a plane (in a certain sense).
Such "elementary questions", called predicates, are functions that take as an argument a (small) number of points (or simple geometric objects) and that returns a set of discrete values.
For instance, consider four points ABOVE
, BELOW
, ON_PLANE
.
These predicates are the "nevralgic" point of mesh intersection methods: if at one moment the
algorithm "thinks" that
In fact, these predicates can be expressed as the sign of a polynomial in the coordinates of the points, and due to the limited precision of floating point numbers, the output of the predicate can be different from the exact mathematical result, especially around zero, and it can depend on the order of the points. Try this: write the following little C program:
#include <stdio.h>
void test_add3(double x, double y, double z) {
printf("%f + %f + %f = %f\n",x,y,z,x+y+z);
}
int main() {
double x1 = 1e30;
double x2 = -1e30;
double x3 = 1e-6;
test_add3(x1,x2,x3);
test_add3(x1,x3,x2);
return 0;
}
The first test computes
Why should we care ? If you think of what may happen in the middle of a geometric algorithm, since the result of an
operation depends on the order of the operands, you may obtain a different result when you ask for the position of
The idea is to implement a C++ class expansion_nt
that represents numbers exactly. How is it possible in a computer ? First thing,
we will implement a very limited set of operations:
- addition:
expansion_nt
+expansion_nt
$rightarrow$ expansion_nt
- subtraction:
expansion_nt
-expansion_nt
$rightarrow$ expansion_nt
- product:
expansion_nt
*expansion_nt
$rightarrow$ expansion_nt
- sign:
expansion_nt
$rightarrow$ NEGATIVE
,ZERO
,POSITIVE
-
Want to learn more about how it works ? See this article and this one
To gain more speed and more robustness in the extreme cases, read about GeogramPlus.