proj home

Files   Classes   Functions   Hierarchy  

main.cpp File Reference

#include <cassert>
#include <iostream>
#include <vector>
#include <climits>
#include <cmath>
#include <aclock.h>
#include <bernsteintest.h>
#include <binoppropertiestest.h>
#include <commandline.h>
#include <d2homogeneoustest.h>
#include <disktest.h>
#include <fixedpointtest.h>
#include <functest.h>
#include <gausselimtest.h>
#include <halfspaceD2test.h>
#include <halfspaceD3test.h>
#include <histogramtest.h>
#include <linechoppedtest.h>
#include <linetest.h>
#include <mathlib.h>
#include <mathlibtest.h>
#include <planetest.h>
#include <point.h>
#include <pointtest.h>
#include <powerseriestest.h>
#include <print.h>
#include <randomtest.h>
#include <simplexD1linkedtest.h>
#include <vectest.h>
#include <zero.h>

Include dependency graph for main.cpp:

Go to the source code of this file.

Typedefs

typedef point2< double > pt2

Functions

void test03 ()
void test04 ()
void test06 ()
void test07 ()
void test10 ()
void test11 ()
void test12 ()
void test13 ()
void test014 ()
void test016 ()
void test017data (vector< point2< double > > &v, uintc n)
void test017 ()
void test018 ()
void test021 ()
void test022 ()
int main (int argc, char **argv)


Typedef Documentation

typedef point2<double> pt2

Definition at line 37 of file main.cpp.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 550 of file main.cpp.

References d2homogeneoustest01(), simplexD1linkedtest::doc, commandline::mapvar(), disktest::test00(), simplexD1linkedtest::test01(), histogramtest::test01(), linetest::test01(), halfspaceD3test::test01(), halfspaceD2test::test01(), binoppropertiestest::test01(), pointtest::test01(), planetest::test01(), mathlibtest::test01(), bernsteintest::test01(), powerseriestest::test01(), randomtest::test01(), functest::test01(), vectest::test01(), gausselimtest::test01(), mathlibtest::test010(), mathlibtest::test011(), test014(), mathlibtest::test015(), test016(), test017(), test018(), linetest::test02(), fixedpointtest::test02(), halfspaceD3test::test02(), halfspaceD2test::test02(), binoppropertiestest::test02(), pointtest::test02(), planetest::test02(), mathlibtest::test02(), powerseriestest::test02(), randomtest::test02(), functest::test02(), vectest::test02(), gausselimtest::test02(), test021(), test022(), fixedpointtest::test03(), halfspaceD3test::test03(), binoppropertiestest::test03(), pointtest::test03(), planetest::test03(), mathlibtest::test03(), randomtest::test03(), functest::test03(), binoppropertiestest::test04(), mathlibtest::test04(), randomtest::test04(), functest::test04(), binoppropertiestest::test05(), mathlibtest::test05(), randomtest::test05(), functest::test05(), mathlibtest::test06(), randomtest::test06(), functest::test06(), functest::test07(), mathlibtest::test07(), randomtest::test07(), functest::test08(), linechoppedtest::unittest01(), linetest::unittest01(), halfspaceD2test::unittest01(), and linechoppedtest::unittest02().

00551 {
00552   commandline cmd(argc,argv);
00553   uint prog(0);
00554   cmd.mapvar(prog,"prog");
00555 
00556   switch (prog)
00557   {
00558     case 0:
00559       cout << "Test programs for mathlib workspace" << endl;
00560       cout << "$./main prog=1..2      - Gaussian elimination tests." << endl;
00561       cout << "$./main prog=40..41    - Power series tests" << endl;
00562 
00563       cout << "$./main prog=17        - Testing line segment intersection algorithms" << endl;
00564       cout << "$./main prog=16        - Testing two line segment intersection" << endl;
00565       cout << "                         (without division)" << endl;
00566       cout << "$./main prog=15        - Testing d2homogeneous class." << endl;
00567       cout << "$./main prog=14        - Testing 3D matrix multiplication." << endl;
00568       cout << "$./main prog=21        - Testing tetrahedron volume calc." << endl;
00569       cout << "$./main prog=22..23    - Testing vec" << endl;
00570       cout << "$./main prog=25..30    - Testing func.h" << endl;
00571       cout << "$./main prog=31..35    - Testing random.h" << endl;
00572       cout << "$./main prog=55        - Testing intervalintersection." << endl;
00573       cout << "$./main prog=70..74    - Testing permfunc and binopproperties classes." << endl;
00574 
00575       cout << "$./main prog=131       - Line test." << endl;
00576       cout << "$./main prog=140       - Histogram test." << endl;
00577       cout << "$./main prog=145       - " << simplexD1linkedtest::doc[1] << endl;
00578       cout << "$./main prog=180-181    - Testing funcstate.h" << endl;
00579       break;
00580 
00581     case 1: gausselimtest::test01(); break;
00582     case 2: gausselimtest::test02(); break;
00583 
00584     case 18: test018(); break;
00585     case 17: test017(); break;
00586     case 16: test016(); break;
00587     case 15: d2homogeneoustest01(); break;
00588     case 14: test014(); break;
00589 
00590     case 21: test021(); break;
00591     case 22: vectest::test01(); break;
00592     case 23: vectest::test02(); break;
00593 
00594     case 25: functest::test01(); break;
00595     case 26: functest::test02(); break;
00596     case 27: functest::test03(); break;
00597     case 28: functest::test04(); break;
00598     case 29: functest::test05(); break;
00599     case 30: functest::test06(); break;
00600     case 31: return randomtest::test01(); 
00601     case 32: return randomtest::test02(); 
00602     case 33: return randomtest::test03();
00603     case 34: return randomtest::test04();
00604     case 35: return randomtest::test05();
00605     case 36: randomtest::test06(); break;
00606     case 37: randomtest::test07(); break;
00607 
00608     case 40: powerseriestest::test01(); break;
00609     case 41: powerseriestest::test02(); break;
00610 
00611     case 45: test022(); break;
00612     case 46: bernsteintest::test01(); break;
00613 
00614     case 50: mathlibtest::test01(argc,argv); break;
00615     case 51: mathlibtest::test02(argc,argv); break;
00616     case 52: mathlibtest::test03(); break;
00617 
00618     case 55: mathlibtest::test04(argc,argv); break;
00619     case 56: mathlibtest::test05(); break;
00620     case 57: mathlibtest::test06(argc,argv); break;
00621     case 58: mathlibtest::test07(argc,argv); break;
00622 
00623     case 60: planetest::test01(argc,argv); break;
00624     case 61: planetest::test02(argc,argv); break;
00625     case 62: planetest::test03(argc,argv); break;
00626 
00627     case 65: pointtest::test01(); break;
00628     case 66: pointtest::test02(); break;
00629     case 67: pointtest::test03(); break;
00630 
00631     case 70: binoppropertiestest::test01(); break;
00632     case 71: binoppropertiestest::test02(); break;
00633     case 72: binoppropertiestest::test03(); break;
00634     case 73: binoppropertiestest::test04(); break;
00635     case 74: binoppropertiestest::test05(); break;
00636 
00637     case 80: halfspaceD2test::test01(); break;
00638     case 81: halfspaceD2test::test02(); break;
00639     case 82: return halfspaceD2test::unittest01(); 
00640     case 85: halfspaceD3test::test01(); break;
00641     case 86: halfspaceD3test::test02(); break;
00642     case 87: halfspaceD3test::test03(argc,argv); break;
00643 
00644     case 90: disktest::test00(); break;
00645 
00646     case 100: mathlibtest::test010(); break;
00647     case 101: mathlibtest::test011(); break;
00648     case 105: mathlibtest::test015(); break;
00649 
00650     case 110: fixedpointtest::test02(); break;
00651     case 111: fixedpointtest::test03(); break;
00652 
00653     case 131: linetest::test01(); break;
00654     case 132: linetest::test02(); break;
00655     case 133: return linetest::unittest01();
00656 
00657     case 135: linechoppedtest::unittest01(); break;
00658     case 136: linechoppedtest::unittest02(); break;
00659 
00660     case 140: histogramtest::test01(argc,argv); break;
00661     
00662     case 145: simplexD1linkedtest::test01(); break;
00663 
00664     case 180: functest::test07(); break;
00665     case 181: functest::test08(); break;
00666 
00667     default: cout << "error:  No case handled." << endl; return 1;
00668   }
00669 
00670   return 0;
00671 }

void test014 (  ) 

Definition at line 312 of file main.cpp.

References matrixmult(), and SHOW.

Referenced by main().

00313 {
00314   cout << "Testing 3D matrix multiplication." << endl;
00315 
00316   doublec m1[] = 
00317   { 
00318     1.0, 2.0, 3.0,
00319     4.0, 5.0, 6.0,
00320     7.0, 8.0, 9.0
00321   };
00322 
00323   point3<double> const x0(1.0,1.0,1.0);
00324   point3<double> x(x0);
00325 
00326   cout << SHOW(x) << endl;
00327 
00328   cout << "multiply with double * matrix" << endl;
00329 
00330   point3<double> y(x);
00331   matrixmult(x,m1,y);
00332   cout << SHOW(x) << endl;
00333 
00334   point3<double> r0(m1[0],m1[1],m1[2]);
00335   point3<double> r1(m1[3],m1[4],m1[5]);
00336   point3<double> r2(m1[6],m1[7],m1[8]);
00337 
00338   cout << "multiply with rows as 3D points for the matrix" << endl;
00339   matrixmult(x,r0,r1,r2,x0);
00340   cout << SHOW(x) << endl;
00341   
00342 }

void test016 (  ) 

Definition at line 346 of file main.cpp.

References lineIntersection(), lineSegmentIntersection(), and SHOW.

Referenced by main().

00347 {
00348   cout << "Testing line segment intersection" << endl;
00349 
00350   point2<double> p1(0.0,0.0);
00351   point2<double> p2(1.0,0.0);
00352   point2<double> q1(0.5,0.0);
00353   point2<double> q2(0.5,1.0);
00354 
00355   cout << SHOW(p1) << " " << SHOW(p2) << endl;
00356   cout << SHOW(q1) << " " << SHOW(q2) << endl;
00357 
00358   cout << "Without division algorithm: " << endl;
00359 
00360   bool const res = lineSegmentIntersection(p1,p2,q1,q2,1E-5);
00361   cout << SHOW(res) << endl;
00362   cout << endl;
00363 
00364   cout << "With One division" << endl;
00365   double tp,tq;
00366   bool const res2 = lineIntersection(tp,tq,p1,p2,q1,q2,1E-5);
00367   cout << SHOW(res2) << endl;
00368   cout << SHOW(tp) << "  (" << p1 + (p2-p1)*tp << ")" << endl;
00369   cout << SHOW(tq) << "  (" << q1 + (q2-q1)*tq << ")" << endl;
00370   cout << endl;
00371 }

void test017 (  ) 

Definition at line 381 of file main.cpp.

References aclock::diff_ms(), lineSegmentIntersection(), aclock::measure(), SHOW, and test017data().

Referenced by main().

00382 {
00383   cout << "Testing line segment intersection algorithms" << endl;
00384   cout << "Algorithm A has no divisions, Algorithm B has one" <<endl;
00385   cout << "Generating test data : random points in a unit cube" << endl;
00386 
00387   uintc n = 100000;
00388   cout << n << " lines are being intersected" << endl;
00389   
00390   vector< point2<double> > v;
00391   test017data(v,n);
00392 
00393   vector<bool> b0(n);
00394 
00395   uint k;
00396 
00397   aclock clk;
00398 
00399   clk.measure();
00400   for (uint i=0; i<n; ++i)
00401   {
00402     k = i*4;
00403     b0[i] = lineSegmentIntersection(v[k],v[k+1],v[k+2],v[k+3],1E-5);
00404   } 
00405   clk.measure();
00406   cout << SHOW(clk.diff_ms()) << endl;
00407 
00408   cout << "Algorithm B has one division" << endl;
00409   vector<bool> b1(n);
00410   double t1,t2;
00411 
00412   clk.measure();
00413   for (uint i=0; i<n; ++i)
00414   {
00415     k = i*4;
00416     b1[i] = lineSegmentIntersection(t1,t2,v[k],v[k+1],v[k+2],v[k+3],1E-5);
00417   } 
00418   clk.measure();
00419   cout << SHOW(clk.diff_ms()) << endl;
00420 
00421   uint count=0;
00422   for (uint i=0; i<n; ++i)
00423   {
00424     if (b0[i]!=b1[i])
00425       ++count;
00426   }
00427 
00428   cout << "Checking the two algorithms for differences in intersection results" << endl;
00429   cout << "  differences = " << count << endl;
00430 
00431   cout << "My results : for optimized compiler option there was no speed difference" << endl;
00432   cout << "  between algorithms A and B. ie the division was as fast as the integer version." << endl;
00433   cout << "  Since the division algorithm B also calculates the intersection point it is superior." << endl;
00434   cout << "  This result must be because of the processor." << endl;
00435 
00436 }

void test017data ( vector< point2< double > > &  v,
uintc  n 
)

Definition at line 373 of file main.cpp.

Referenced by test017(), and test018().

00374 {
00375   doublec w = 1.0 / LONG_MAX;
00376 
00377   for (uint i=0; i<n*4; ++i)
00378     v.push_back( point2<double>(w*rand(),w*rand()) );
00379 }

void test018 (  ) 

Definition at line 438 of file main.cpp.

References aclock::diff_ms(), lineIntersection(), lineintersection(), aclock::measure(), SHOW, and test017data().

Referenced by main().

00439 {
00440   cout << "Comparing timings for line intersection with algorithm B and C" << endl;
00441 
00442   uintc n = 100000;
00443   cout << n << " lines are being intersected" << endl;
00444 
00445   vector< point2<double> > v;
00446   test017data(v,n);
00447 
00448   vector<bool> b0(n);
00449 
00450   uint k;
00451 
00452   aclock clk;
00453   double t1,t2;
00454 
00455   cout << "Algorithm C uses a 2D matrix solver" << endl;
00456 
00457   clk.measure();
00458   for (uint i=0; i<n; ++i)
00459   {
00460     k = i*4;
00461     b0[i] = lineintersection(t1,t2,v[k],v[k+1],v[k+2],v[k+3]);
00462   } 
00463   clk.measure();
00464   cout << SHOW(clk.diff_ms()) << endl;
00465 
00466   cout << "Algorithm B has one division" << endl;
00467   vector<bool> b1(n);
00468 
00469   clk.measure();
00470   for (uint i=0; i<n; ++i)
00471   {
00472     k = i*4;
00473     b1[i] = lineIntersection(t1,t2,v[k],v[k+1],v[k+2],v[k+3],1E-5);
00474   } 
00475   clk.measure();
00476   cout << SHOW(clk.diff_ms()) << endl;
00477 
00478   uint count=0;
00479   for (uint i=0; i<n; ++i)
00480   {
00481     if (b0[i]!=b1[i])
00482       ++count;
00483   }
00484 
00485   cout << "Checking the two algorithms for differences in intersection results" << endl;
00486   cout << "  differences = " << count << endl;
00487 }

void test021 (  ) 

Definition at line 491 of file main.cpp.

References SHOW, and tetrahedronvolume().

Referenced by main().

00492 {
00493   cout << "Testing the volume of a tetraheron calc." << endl;
00494 
00495   doublec a2[] = 
00496   {
00497     0.0, 0.0, 0.0,
00498     1.0, 0.0, 0.0,
00499     1.0, 1.0, 0.0,
00500     0.0, 1.0, 0.0,
00501     0.0, 0.0, 1.0,
00502     1.0, 0.0, 1.0,
00503     1.0, 1.0, 1.0,
00504     0.0, 1.0, 1.0
00505   };
00506 
00507   uint n=8;
00508 
00509   typedef point3<double> pt3;
00510   vector< pt3 > v2;
00511   for (uint i=0; i<n; ++i)
00512     v2.push_back( pt3(a2[i*3],a2[i*3+1],a2[i*3+2]) ); 
00513 
00514 
00515   double volume;
00516   tetrahedronvolume(volume,v2[0],v2[1],v2[5],v2[6]);
00517   cout << SHOW(volume) << endl;
00518 
00519   double s=0.0;
00520   s += abs(volume);
00521   tetrahedronvolume(volume,v2[0],v2[6],v2[2],v2[1]);
00522   cout << SHOW(volume) << endl;
00523   s += abs(volume);
00524   tetrahedronvolume(volume,v2[2],v2[6],v2[0],v2[3]);
00525   cout << SHOW(volume) << endl;
00526   s += abs(volume);
00527   cout << SHOW(s) << endl;
00528 
00529   cout << "The sum should be 0.5 or half the volume of a unit cube" << endl;
00530 
00531 }

void test022 (  ) 

Definition at line 533 of file main.cpp.

References mathcombination(), and SHOW.

Referenced by main().

00534 {
00535   cout << "Combination" << endl;
00536   cout << "Enter n k" << endl;
00537   uint n,k;
00538   cin >> n >> k;
00539   double res;
00540   mathcombination(res,n,k);
00541   cout << SHOW(res) << endl;
00542 }

void test03 (  ) 

Definition at line 81 of file main.cpp.

References crossproduct::eval(), and print().

00082 {
00083 
00084   vector<double> a1(3);
00085   a1[0] = 1;
00086   a1[1] = 0;
00087   a1[2] = 0;
00088 
00089   vector<double> a2(3), a3(3);
00090 
00091   a2[0] = 0;
00092   a2[1] = 1;
00093   a2[2] = 0;
00094 
00095   //surfaceplane< vector<double> >()(a2,a3,a1);
00096 
00097   print(a1);
00098   print(a2);
00099   cout << endl;
00100   //crossprod< vector<double> >()(a3,a1,a2);
00101   crossproduct::eval(a3,a1,a2);
00102 
00103   print(a3);
00104 
00105   cout << "And the reverse process, from a normal" << endl;
00106   cout << "generate a surface plane." << endl;
00107 
00108   vector<double> u(3), v(3), t(3);
00109   surfaceplane< vector<double> >()(u,v,t,a3); 
00110   cout << "u=";
00111   print(u);
00112   cout << "v=";
00113   print(v);
00114   cout << "w=";
00115   print(a3);
00116 
00117 }

void test04 (  ) 

Definition at line 129 of file main.cpp.

00130 {
00131 
00132   convexity<double> c;
00133   bool res;
00134 
00135   f1 f;
00136 
00137   unsigned int n;
00138   double a;
00139   double b;
00140 
00141   cout << "Testing convextity test." << endl;
00142   cout << "Enter n a b where n is the number of points" << endl;
00143   cout << "  sampled on (a,b). n=0 terminates." << endl;
00144 
00145   for ( ; ; )
00146   {
00147 
00148     cin >> n;
00149     if (n==0)
00150       return;
00151 
00152     cin >> a;
00153     cin >> b;
00154 
00155     c(res,f,n,a,b);
00156     cout << "res=" << res << endl;
00157   }
00158 
00159 }

void test06 (  ) 

Definition at line 207 of file main.cpp.

References determinant::calcD2(), and trianglearea().

00208 {
00209 
00210   cout << "Triangle Area Calculation" << endl;
00211   
00212   cout << "x0 y0 x1 y1 x2 y2" << endl;
00213   double x0,y0,x1,y1,x2,y2;
00214   cin >> x0;
00215   cin >> y0;
00216   cin >> x1;
00217   cin >> y1;
00218   cin >> x2;
00219   cin >> y2;
00220   double f;
00221   trianglearea(f,x0,y0,x1,y1,x2,y2);
00222   cout << "area=" << f << endl;
00223 
00224   
00225   cout << "area=" << 0.5*determinant::calcD2(x1-x0,x2-x0,y1-y0,y2-y0) << endl;
00226 
00227 }

void test07 (  ) 

Definition at line 230 of file main.cpp.

References d2matsolve().

00231 {
00232   pt2 x;
00233 
00234   d2matsolve(x, pt2(3.0,2.0), pt2(1.0,1.0), pt2(7.0,3.0) );
00235   cout << "x=" << x << endl;
00236 
00237 }

void test10 (  ) 

Definition at line 245 of file main.cpp.

References SHOW, trianglearea(), point3< T >::x, and point3< T >::y.

Referenced by main().

00246 {
00247   cout << "Testing Area of Triangle Formula in 3D" << endl;
00248 
00249   point3<double> p0(0.0,0.0,0.0);
00250   point3<double> p1(3.0,0.0,0.0);
00251   point3<double> p2(3.0,4.0,0.0);
00252 
00253   double a1;
00254   trianglearea(a1,p0.x,p0.y,p1.x,p1.y,p2.x,p2.y);
00255   cout << SHOW(a1) << endl;
00256 
00257   double a2;
00258 
00259   trianglearea(a2,p0,p1,p2);
00260   cout << SHOW(a2) << endl;
00261 
00262 
00263 }

void test11 (  ) 

Definition at line 265 of file main.cpp.

References solvequadratic(), point2< T >::x, and point2< T >::y.

00266 {
00267   cout << "Testing solvequadratic" << endl;
00268   cout << "Solve (x-2)*(x+3)=0" << endl;
00269   // x^2 + x - 6 = 0
00270   pt2 x;
00271   solvequadratic(x.x,x.y,1.0,1.0,-6.0);
00272   cout << "x=" << x << endl;
00273 }

void test12 (  ) 

Definition at line 275 of file main.cpp.

References lineintersection(), and SHOW.

00276 {
00277   cout << "Test intersecting lines equation" << endl;
00278  
00279   pt2 a(1.0,1.0);
00280   pt2 b(5.0,1.0);
00281 
00282   pt2 c(2.0,-1.0);
00283   pt2 d(2.0, 7.0);
00284 
00285   double t0;
00286   double t1;
00287 
00288   bool res;
00289 
00290   res = lineintersection(t0,t1,a,b,c,d);
00291   cout << SHOW(res) << endl;
00292   cout << "(" << a << "," << b << "): " << a+(b-a)*t0 << endl;
00293   cout << "(" << c << "," << d << "): " << c+(d-c)*t1 << endl;
00294 
00295 }

void test13 (  ) 

Definition at line 297 of file main.cpp.

References transrotate2D::eval(), r, and SHOW.

00298 {
00299   cout << "Test rotating a 2D point about the origin" << endl;
00300 
00301   point2<double> x(1.0,0.0);
00302 
00303   cout << SHOW(x) << endl;
00304 
00305   doublec pi=3.141592654;
00306   transrotate2D r(pi*0.5);
00307 
00308   r.eval(x);
00309   cout << SHOW(x) << endl;
00310 }


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