1 // Some tests for vgl_sphere
2 // Ian Scott, Aug 2005.
3 #include <iostream>
4 #include <limits>
5 // not used? #include <vcl_compiler.h>
6 #include "testlib/testlib_test.h"
7 #include "vgl/vgl_plane_3d.h"
8 #include "vgl/vgl_line_3d_2_points.h"
9
10 static void
test_plane_intersection()11 test_plane_intersection()
12 {
13 vgl_plane_3d<double> pl1(vgl_vector_3d<double>(10, 10, 10), vgl_point_3d<double>(10, 0, -10));
14
15 TEST("O is a point on pl1 ", pl1.d(), 0.0);
16
17 vgl_line_3d_2_points<double> l1(vgl_point_3d<double>(1, 4, 1), vgl_point_3d<double>(-1, -4, -1));
18 TEST("O is a point on l1", collinear(l1, vgl_point_3d<double>(0, 0, 0)), true);
19
20 vgl_line_3d_2_points<double> l2(vgl_point_3d<double>(0, 0, 0), vgl_point_3d<double>(10, 0, -10));
21 TEST("O is a point on l2", collinear(l2, vgl_point_3d<double>(0, 0, 0)), true);
22 TEST("plane_pt is a point on l2", collinear(l2, vgl_point_3d<double>(10, 0, -10)), true);
23
24 vgl_line_3d_2_points<double> l3(vgl_point_3d<double>(0, 10, 0), vgl_point_3d<double>(10, 10, -10));
25 TEST("O is not on l3", collinear(l3, vgl_point_3d<double>(0, 0, 0)), false);
26 TEST("plane_norm is perpendicular to l3 direction)", dot_product(pl1.normal(), l3.direction()), 0.0);
27 }
28
29 static void
test_direction_vector()30 test_direction_vector()
31 {
32 vgl_point_3d<double> p1(0, 0, 0);
33 vgl_point_3d<double> p2(1, 2, 3);
34 vgl_line_3d_2_points<double> l1(p1, p2);
35 vgl_vector_3d<double> u = p2 - p1;
36 TEST("Direction vector 1", u, l1.direction());
37 }
38
39
40 static void
test_parametric_point()41 test_parametric_point()
42 {
43 vgl_point_3d<double> p1(0, 0, 0);
44 vgl_point_3d<double> p2(1, 2, 4);
45 vgl_point_3d<double> p3(0.5, 1.0, 2.0);
46 vgl_line_3d_2_points<double> l1(p1, p2);
47 TEST("Parametric point: t=0.0", l1.point_t(0.0), p1);
48 TEST("Parametric point: t=1.0", l1.point_t(1.0), p2);
49 TEST("Parametric point: t=0.5", l1.point_t(0.5), p3);
50 TEST("Parametric point: t=-1.0", l1.point_t(-1.0), vgl_point_3d<double>(-1, -2, -4));
51 TEST("Parametric point: t=2.0", l1.point_t(2.0), vgl_point_3d<double>(2, 4, 8));
52 }
53
54
55 void
test_line_3d_2_points()56 test_line_3d_2_points()
57 {
58 std::cout << "********************************\n"
59 << " Testing vgl_line_3d_2_points\n"
60 << "********************************\n\n";
61 test_plane_intersection();
62
63 test_direction_vector();
64
65 test_parametric_point();
66 }
67
68
69 TESTMAIN(test_line_3d_2_points);
70