Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 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,2,3);
18
	norm.normalize();
19
 
20
	Vec3f a,b;
21
 
22
	orthogonal(norm,a,b);
23
 
24
	cout << "The frame " << endl;
25
	cout << norm << a << b << endl;
26
 
27
	vector<Vec3f> vec;
28
	srand(0);
29
	for(int i=0;i<100000;++i)
30
		{
31
			Vec3f p = 1.0f*frand()*norm + 1.02f*frand()*a + 1.05f*frand()*b;
32
			vec.push_back(p);
33
		}
34
 
35
 
36
	Mat3x3f A;
37
	Vec3f m = covariance(vec, A);
38
 
39
	cout << "Mean and covariance " << endl;
40
	cout << m << "\n" << A << endl;
41
 
42
 
43
	Mat3x3f Q,L;
44
	int n = power_eigensolution(A, Q, L);
45
 
46
	cout << "The " << n << " eigensolutions are ";
47
	cout << Q << L << endl;
48
 
49
	cout << "Dot products " 
50
			 << dot(Q[0], Q[1]) << " "
51
			 << dot(Q[0], Q[2]) << " " 
52
			 << dot(Q[1], Q[2]) << endl;
53
}