added new example showing actual feature of Polytope_distance, the

hybrid arithmetic; unfortunately, the only way to make it work
currently is with the inofficial CGAL::Double
This commit is contained in:
Bernd Gärtner 2006-03-13 12:17:55 +00:00
parent 6dc7208959
commit b92b88bc11
3 changed files with 63 additions and 4 deletions

1
.gitattributes vendored
View File

@ -1255,6 +1255,7 @@ Polyhedron/examples/Polyhedron/corner_with_hole.off -text
Polyhedron/examples/Polyhedron/corner_with_sharp_edge.off -text
Polyhedron/examples/Polyhedron/cross.off -text
Polytope_distance_d/examples/Polytope_distance_d/polytope_distance_d.C -text
Polytope_distance_d/examples/Polytope_distance_d/polytope_distance_d_fast_exact.C -text
Polytope_distance_d/test/Polytope_distance_d/create_test_PD_cin -text
Polytope_distance_d/test/Polytope_distance_d/test_PD.C -text
Polytope_distance_d/test/Polytope_distance_d/test_PD.cin -text

View File

@ -1,7 +1,8 @@
// file: examples/Polytope_distance_d/polytope_distance.C
// computes the distance between two cubes in R^3
// computes the distance between two cubes in R^3 using double
// as input type and internal type (prone to roundoff errors)
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polytope_distance_d.h>
#include <CGAL/Optimisation_d_traits_3.h>
@ -25,8 +26,8 @@ int main()
Polytope_distance pd(P, P+8, Q, Q+8);
// get squared distance (2,2,2)-(1,1,1))^2 = 3
std::cout << "Distance (as rational number): " <<
pd.squared_distance_numerator() << " / " <<
std::cout << "Squared distance: " <<
pd.squared_distance_numerator() /
pd.squared_distance_denominator() << std::endl;
// get points that realize the distance

View File

@ -0,0 +1,57 @@
// file: examples/Polytope_distance_d/polytope_distance_fast_exact.C
// computes the distance between two cubes in R^3 using double
// as input type and CGAL::Double as exact internal type; this
// is guaranteed to have no roundoff errors. Note: CGAL::Double
// is based on GMP but not yet an official CGAL number type; in
// this respect, the example represents experimental code
#include <iostream>
#include <CGAL/QP_solver/gmp_double.h> // will become CGAL number type
#include <CGAL/Simple_cartesian.h>
#include <CGAL/QP_solver/Double.h> // will become CGAL number type
#include <CGAL/Polytope_distance_d.h>
#include <CGAL/Optimisation_d_traits_3.h>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point;
typedef CGAL::Optimisation_d_traits_3<K, CGAL::Double, double>
Traits;
typedef CGAL::Polytope_distance_d<Traits> Polytope_distance;
int main()
{
// the cube [0,1]^3
Point P[8] = { Point(0,0,0), Point(0,0,1), Point(0,1,0), Point(0,1,1),
Point(1,0,0), Point(1,0,1), Point(1,1,0), Point(1,1,1)};
// the cube [2,3]^3
Point Q[8] = { Point(2,2,2), Point(2,2,3), Point(2,3,2), Point(2,3,3),
Point(3,2,2), Point(3,2,3), Point(3,3,2), Point(3,3,3)};
Polytope_distance pd(P, P+8, Q, Q+8);
// get squared distance (2,2,2)-(1,1,1))^2 = 3
std::cout << "Squared Distance: " <<
CGAL::to_double(pd.squared_distance_numerator()) /
CGAL::to_double(pd.squared_distance_denominator()) << std::endl;
// get points that realize the distance
Polytope_distance::Coordinate_iterator coord_it;
std::cout << "p:"; // homogeneous point from first cube, (1,1,1,1)
for (coord_it = pd.realizing_point_p_coordinates_begin();
coord_it != pd.realizing_point_p_coordinates_end();
++coord_it)
std::cout << " " << CGAL::to_double(*coord_it);
std::cout << std::endl;
std::cout << "q:"; // homogeneous point from second cube, (2,2,2,1)
for (coord_it = pd.realizing_point_q_coordinates_begin();
coord_it != pd.realizing_point_q_coordinates_end();
++coord_it)
std::cout << " " << CGAL::to_double(*coord_it);
std::cout << std::endl;
return 0;
}