Subversion Repositories gelsvn

Rev

Rev 12 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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