proj home

Files   Classes   Functions   Hierarchy  

linetest.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <line.h>
00005 #include <linetest.h>
00006 #include <point.h>
00007 #include <print.h>
00008 
00009 
00010 void linetest::test01()
00011 {
00012   typedef point2<double> pt2;
00013   typedef point3<double> pt3;
00014 
00015   line<pt2,double> L1(pt2(1.0,1.0),pt2());
00016 
00017   cout << "L1: " << (stringc) L1 << endl;
00018   
00019   double len=5.0;
00020   cout << "Normalize to having nml with " << len << " length." << endl;
00021 
00022   L1.normalize(len);
00023   cout << "L1: " << (stringc) L1 << endl;
00024 
00025   cout << SHOW(L1.nml.distance()) << endl;
00026   cout << SHOW( L1(0.0) ) << endl;
00027   cout << SHOW( L1(1.0) ) << endl;
00028 
00029   cout << "Re normalize." << endl;
00030   L1.normalize();
00031   cout << "L1: " << (stringc) L1 << endl;
00032 
00033   pt2 p2(6.0,6.0);
00034   cout << SHOW(p2) << endl;
00035   cout << "Find the t value of p2." << endl;
00036   double t1;
00037   bool res;
00038   res = L1.tD2(t1,p2);
00039   cout << SHOW(res) << "  " << SHOW(t1) << endl;
00040   cout << SHOW(L1(t1)) << endl;
00041 
00042   cout << endl;
00043   cout << "Testing point minimized to a line." << endl;
00044   double delta=0.1;
00045   cout << SHOW(delta) << endl;
00046   pt2 p3(2.0,3.0);
00047   cout << SHOW(p3) << endl;
00048   cout << "Minimize to L1:" << (stringc)L1 << endl;
00049   L1.nearestpoint(t1,p3);
00050   cout << SHOW((L1(t1-delta)-p3).distance()) << endl;
00051   cout << SHOW((L1(t1)-p3).distance()) << endl;
00052   cout << SHOW((L1(t1+delta)-p3).distance()) << endl;
00053 
00054 }
00055 
00056 
00057 void linetest::test02()
00058 {
00059   typedef point3<double> pt3;
00060 
00061   pt3 pts[] = 
00062   {
00063     pt3(0.0,0.0,0.0),
00064     pt3(1.0,-3.0,2.0),
00065     pt3(.24,.1,-.3),
00066     pt3(-2.0,-10.0,4.3)
00067   };
00068 
00069   line<pt3,double> L1(pts[0],pts[1],true);
00070   line<pt3,double> L2(pts[2],pts[3],true);
00071 
00072   double t1;
00073   double t2;
00074   bool res;
00075   res = L1.lineD3minimized(t1,t2,L2);
00076   cout << SHOW(res) << endl;
00077 
00078   double delta = 0.1;
00079   cout << SHOW(delta) << endl;
00080   
00081   cout << "Varying t1" << endl;
00082   cout << SHOW((L1(t1-delta)-L2(t2)).distance()) << endl;
00083   cout << SHOW((L1(t1)-L2(t2)).distance()) << endl;
00084   cout << SHOW((L1(t1+delta)-L2(t2)).distance()) << endl;
00085   
00086   cout << "Varying t2" << endl;
00087   cout << SHOW((L1(t1)-L2(t2-delta)).distance()) << endl;
00088   cout << SHOW((L1(t1)-L2(t2)).distance()) << endl;
00089   cout << SHOW((L1(t1)-L2(t2+delta)).distance()) << endl;
00090 
00091 }
00092 
00093 int linetest::unittest01()
00094 {
00095   typedef point2<double> pt2;
00096 
00097   line<pt2,double> L1(pt2(0.0,0.0),pt2(8.0,0.0),true);
00098   line<pt2,double> L2(pt2(3.0,-5.0),pt2(3.0,5.0),true);
00099 
00100   double t0;
00101   double t1;
00102 
00103   bool res;
00104   res = L1.intersects(t0,t1,L2);
00105   if (res==false)
00106     return 1;
00107 
00108   cout << SHOW( L1(t0) ) << endl;
00109   cout << SHOW( L2(t1) ) << endl;
00110 
00111   assertreturnOS( zero<double>::test( (L1(t0)-pt2(3.0,0.0)).dot() ) );
00112 
00113   return 0;
00114 }
00115 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8