plane_intersect.C

00001 #include <string>
00002 #include <iostream>
00003 #include <iomanip>
00004 #include <archon/math/geometry.H>
00005 #include <archon/util/random.H>
00006 
00007 using namespace std;
00008 using namespace Archon::Math;
00009 using namespace Archon::Utilities;
00010 
00011 int main(int argc, const char *argv[]) throw()
00012 {
00013   // The six planes of a box
00014   //   l - left
00015   //   r - right
00016   //   d - down
00017   //   u - up
00018   //   f - far
00019   //   n - near
00020 
00021   // Normals
00022   Vector3 n_l(-1,  0,  0);
00023   Vector3 n_r( 1,  0,  0);
00024   Vector3 n_d( 0, -1,  0);
00025   Vector3 n_u( 0,  1,  0);
00026   Vector3 n_f( 0,  0, -1);
00027   Vector3 n_n( 0,  0,  1);
00028 
00029   // Fixed points
00030   Vector3 p_l(-1,  0,  0);
00031   Vector3 p_r( 1,  0,  0);
00032   Vector3 p_d( 0, -1,  0);
00033   Vector3 p_u( 0,  1,  0);
00034   Vector3 p_f( 0,  0, -1);
00035   Vector3 p_n( 0,  0,  1);
00036 
00037   // Generate random but limited rotations
00038   Rotation3 r_l(drawUnitVector3(), M_PI/12);
00039   Rotation3 r_r(drawUnitVector3(), M_PI/12);
00040   Rotation3 r_d(drawUnitVector3(), M_PI/12);
00041   Rotation3 r_u(drawUnitVector3(), M_PI/12);
00042   Rotation3 r_f(drawUnitVector3(), M_PI/12);
00043   Rotation3 r_n(drawUnitVector3(), M_PI/12);
00044 
00045   // Distort normals
00046   Matrix3x3(r_l).map(n_l);
00047   Matrix3x3(r_r).map(n_r);
00048   //Matrix3x3(r_d).map(n_d);
00049   Matrix3x3(r_u).map(n_u);
00050   Matrix3x3(r_f).map(n_f);
00051   Matrix3x3(r_n).map(n_n);
00052 
00053   // Construct planes
00054   Plane3 pl_l(n_l, p_l);
00055   Plane3 pl_r(n_r, p_r);
00056   Plane3 pl_d(n_d, p_d);
00057   Plane3 pl_u(n_u, p_u);
00058   Plane3 pl_f(n_f, p_f);
00059   Plane3 pl_n(n_n, p_n);
00060 
00061   // Construct box corners as plane intersections
00062   Vector3 l_d_f = intersect(pl_l, pl_d, pl_f);
00063   Vector3 r_d_f = intersect(pl_r, pl_d, pl_f);
00064   Vector3 l_u_f = intersect(pl_l, pl_u, pl_f);
00065   Vector3 r_u_f = intersect(pl_r, pl_u, pl_f);
00066   Vector3 l_d_n = intersect(pl_l, pl_d, pl_n);
00067   Vector3 r_d_n = intersect(pl_r, pl_d, pl_n);
00068   Vector3 l_u_n = intersect(pl_l, pl_u, pl_n);
00069   Vector3 r_u_n = intersect(pl_r, pl_u, pl_n);
00070 
00071   // Print it
00072   cerr << setprecision(100)
00073        << l_d_f[0] << " " << l_d_f[1] << " " << l_d_f[2] << "\n"
00074        << r_d_f[0] << " " << r_d_f[1] << " " << r_d_f[2] << "\n"
00075        << l_u_f[0] << " " << l_u_f[1] << " " << l_u_f[2] << "\n"
00076        << r_u_f[0] << " " << r_u_f[1] << " " << r_u_f[2] << "\n"
00077        << "\n"
00078        << l_d_n[0] << " " << l_d_n[1] << " " << l_d_n[2] << "\n"
00079        << r_d_n[0] << " " << r_d_n[1] << " " << r_d_n[2] << "\n"
00080        << l_u_n[0] << " " << l_u_n[1] << " " << l_u_n[2] << "\n"
00081        << r_u_n[0] << " " << r_u_n[1] << " " << r_u_n[2] << "\n"
00082        << "\n";
00083 
00084   return 0;
00085 }

Generated on Sun Jul 30 22:55:43 2006 for Archon by  doxygen 1.4.4