cgal/Packages/Intersections_3/test/Intersections_3/plane_seg.C

99 lines
2.0 KiB
C

#include "numrep1.h"
#include <CGAL/Plane_3.h>
#include <CGAL/Line_3.h>
#include <CGAL/intersection_3_1.h>
#include "numrep2.h"
using std::cout;
using std::cin;
typedef CGAL::Plane_3<TestR> Plane;
typedef CGAL::Segment_3<TestR> Segment;
typedef CGAL::Point_3<TestR> Point;
typedef CGAL::Direction_3<TestR> Direction;
bool read_data(Plane &pl, Segment &seg)
{
randomint ri;
int a, b, c, d, w;
cin >> a >> b >> c >> d;
if (!cin)
return false;
w = ri.next();
pl = Plane(a*w, b*w, c*w, d*w);
cin >> a >> b >> c;
if (!cin)
return false;
w = ri.next();
Point p1(a*w, b*w, c*w, w);
cin >> a >> b >> c;
if (!cin)
return false;
w = ri.next();
Point p2(a*w, b*w, c*w, w);
seg = Segment(p1, p2);
return true;
}
void write_point(const Point & pt)
{
double xd = CGAL::to_double(pt.x());
double yd = CGAL::to_double(pt.y());
double zd = CGAL::to_double(pt.z());
// force 0 to be positive zero.
if (xd == 0.0)
xd = 0.0;
if (yd == 0.0)
yd = 0.0;
if (zd == 0.0)
zd = 0.0;
cout << xd <<' '<< yd <<' '<< zd << '\n';
}
/*
void write_point(const Point & pt)
{
cout << CGAL::to_double(pt.x()) <<' '
<< CGAL::to_double(pt.y()) <<' '
<< CGAL::to_double(pt.z()) << '\n';
}
*/
int main()
{
Plane pl;
Point pt;
Segment seg;
CGAL::Object result;
if (!read_data(pl, seg))
return 1;
result = CGAL::intersection(pl, seg);
if (result.is_empty()) {
if (CGAL::do_intersect(pl, seg)) {
cout << "do_intersect is inconsistent with intersection result.\n";
return 1;
}
cout << "No intersection.\n";
return 0;
}
if (!CGAL::do_intersect(pl, seg)) {
cout << "do_intersect is inconsistent with intersection result.\n";
return 1;
}
if (CGAL::assign(pt, result)) {
cout << "Point intersection.\n";
write_point(pt);
return 0;
} else {
if (CGAL::assign(seg, result)) {
cout << "Segment intersection.\n";
return 0;
}
}
cout << "Unknown result.\n";
return 1;
}