Subversion Repositories gelsvn

Rev

Rev 194 | Rev 343 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
#include <iostream>
326 jab 2
#include <algorithm>
107 bj 3
 
326 jab 4
#include "CGLA/Mat4x4d.h"
107 bj 5
#include "CGLA/Mat4x4f.h"
6
#include "CGLA/Mat2x2f.h"
7
#include "CGLA/Mat3x3f.h"
8
#include "CGLA/Mat2x3f.h"
9
#include "CGLA/eigensolution.h"
10
 
11
#include "CGLA/Vec2f.h"
12
#include "CGLA/Vec2i.h"
13
#include "CGLA/Vec3i.h"
14
#include "CGLA/Vec3f.h"
15
#include "CGLA/Vec3Hf.h"
16
 
17
using namespace std;
18
using namespace CGLA;
19
 
20
 
21
/* This is a non-exhaustive test program for CGLA */
194 jrf 22
int main()
107 bj 23
{
24
 
25
	Mat2x3f m23(Vec3f(1,1,1),Vec3f(2,2,2));
26
	Mat3x2f m32;
27
 
28
	// Try transpose of non-sq matrix
29
	transpose(m23, m32);
30
	cout << "2 by 3 " << m23 << endl;
31
	cout << "Transpose " << m32 << endl;
32
 
33
 
34
	m32[0] = Vec2f(1,2);
35
	m32[1] = Vec2f(10,20);
36
	m32[2] = Vec2f(100,200);
37
 
38
	Mat2x2f m22;
39
 
40
	// Multiply 2x3 and 3x2 matrices
41
	mul(m23, m32, m22);
42
	cout << "Multiplication of non. sq. mat " << m22 << endl;
43
 
44
	// Check matrix mul using * operator for sq matrices.
45
	Mat2x2f m22_2(1,2,3,4);
46
	cout << "multiplication of sq. mats " << m22_2 * m22 << endl;
47
	cout << "Trace " << trace(m22) << endl;
48
 
49
	m22_2 += m22 + m22;
50
	m22_2 -= 2* m22;
51
 
52
	Mat4x4f m44(0.0f);
53
	m44[0][0] = 1;
54
	m44[1][2] = 2;
55
	m44[2][1] = 3;
56
	m44[3][3] = 4;
57
 
58
	Mat4x4f m44_2 = transpose(m44);
59
	cout << m44 << m44_2 << endl; 
60
 
61
	// Compile should fail if line below is uncommented
62
	// mul(m23, m44, m22);
63
	// Compile should fail if line below is uncommented
64
	// transpose(m23,m44);
65
 
66
	cout << "Determinant of 4x4 " << m44 << determinant(m44) << endl;
67
	cout << "Determinant of 2x2 " << m22 << determinant(m22) << endl;
68
 
69
	Mat4x4f mna(Vec4f(10,120,10,40),
70
							Vec4f(43,10,31254,10),
71
							Vec4f(43,11,54,10),
72
							Vec4f(0,0,0,1));
73
 
74
	cout << fixed << endl;
75
	try
76
		{
77
			cout << "Invert: " << invert_affine(mna) << endl;
78
			cout << "Test: " << invert_affine(mna)*mna << endl;
79
		}
80
	catch(const Mat4x4fException& me)
81
		{
82
			me.print(cout);
83
		}
84
	try
85
		{	
86
			cout << "Invert " << invert(mna) << endl;
87
			cout << "test " << invert(mna)*mna << endl;
88
		}
89
	catch(const Mat4x4fException& me)
90
		{
91
			me.print(cout);
92
		}
93
 
94
	Vec2f v2(2,3);
95
	Vec3f v3(1,2,3);
96
	Mat2x3f m23_2;
97
	outer_product(v2,v3,m23_2);
98
	cout << "outer product of " << v2 << " , " << v3 << " = " << m23_2 << endl;
99
 
100
	Mat4x4f A(Vec4f(1, 2, 3, 4), 
101
						Vec4f(2, 9,-7,2), 
102
						Vec4f(3,-7, 8, 1),
103
						Vec4f(4,2, 31,12)
104
						);
105
	Mat4x4f Q,L;
106
 
107
	int n = power_eigensolution(A, Q, L);
108
 
109
	cout << "The " << n << " eigensolutions of " << A << " are ";
110
	cout << Q << L << endl;
111
 
112
	m44 = identity_Mat4x4f();
113
 
114
	Mat3x3f m33(Vec3f(1,2,3), Vec3f(4,5,6), Vec3f(7,8,9));
115
 
116
	copy_matrix(m33, m44);
117
 
118
	cout << "The matrix " << m33 << " is copied to " << m44 << endl;
119
 
326 jab 120
	cout << "Determinant of singular 4x4 matrix" << endl;
107 bj 121
 
326 jab 122
 	Mat4x4d m_odd(Vec4d(0, 373, 139129, 1),
123
 								Vec4d(-373, -125, 154754, 1),
124
 								Vec4d(-50.6168, 21.2469, 3013.5, 100),
125
 								Vec4d(-50.6168, 21.2469, 3013.5, 100));
126
 
127
	cout << m_odd << endl;
128
	cout << "Determinant: " << determinant(m_odd) << endl;
129
 
130
	Mat4x4d m_odd_t = transpose(m_odd);
131
 
132
	cout << m_odd_t << endl;
133
	cout << "Det of transpose:" << determinant(m_odd_t) << endl;
134
 
135
	cout << "Determinant of random matrix (MatLab says 0.0491)" << endl;
136
 
137
 
138
	Mat4x4d Mrand(Vec4d(0.9169,0.3529,0.2028,0.1988),
139
								Vec4d(0.4103,0.8132,0.1987,0.0153),
140
								Vec4d(0.8936,0.0099,0.6038,0.7468),
141
								Vec4d(0.0579,0.1389,0.2722,0.4451));
142
 
143
	cout << "det " << determinant(Mrand) << endl;
144
	cout << "det of transpose " << determinant(transpose(Mrand)) << endl;
145
 
194 jrf 146
	return 0;
107 bj 147
}