Subversion Repositories gelsvn

Rev

Rev 193 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
#include <iostream>
2
 
3
#include "CGLA/Vec3f.h"
4
#include "CGLA/Mat3x3f.h"
5
#include "CGLA/statistics.h"
6
#include "CGLA/eigensolution.h"
7
 
8
using namespace std;
9
using namespace CGLA;
10
 
11
 
12
float frand() { return static_cast<float>(rand())/RAND_MAX - 0.5f;}
13
 
14
/* This is a non-exhaustive test program for CGLA */
15
main()
16
{
17
    Vec3f norm(1,0,0);
18
    norm.normalize();
19
 
20
    Vec3f a,b;
21
    orthogonal(norm,a,b);
22
 
23
    cout << "The frame " << endl;
24
    cout << norm << a << b << endl;
25
 
26
    vector<Vec3f> vec;
27
    srand(0);
28
    for(int i=0;i<100000;++i)
29
    {
30
	Vec3f p = 1.0f*frand()*norm + 2.02f*frand()*a + 3.05f*frand()*b;
31
	vec.push_back(p);
32
    }
33
 
34
    Mat3x3f A(0);
35
    Vec3f m = covariance(vec, A);
36
 
37
    cout << "Mean and covariance " << endl;
38
    cout << m << "\n" << A << endl;
39
 
40
 
41
    Mat3x3f Q,L;
42
    int n = power_eigensolution(A, Q, L);
43
 
44
    cout << "The " << n << " eigensolutions are ";
45
    cout << Q << L << endl;
46
 
47
    cout << "Dot products " 
48
	<< dot(Q[0], Q[1]) << " "
49
	<< dot(Q[0], Q[2]) << " " 
50
	<< dot(Q[1], Q[2]) << endl;
51
}