Revision 1025,
774 bytes
checked in by gumbau, 18 years ago
(diff) |
namespace simplif
|
Line | |
---|
1 | #include <gfx/std.h>
|
---|
2 | #include <gfx/math/Mat2.h>
|
---|
3 |
|
---|
4 | using namespace simplif;
|
---|
5 |
|
---|
6 | Mat2 Mat2::identity(Vec2(1,0), Vec2(0,1));
|
---|
7 | Mat2 Mat2::zero(Vec2(0,0), Vec2(0,0));
|
---|
8 | Mat2 Mat2::unit(Vec2(1,1), Vec2(1,1));
|
---|
9 |
|
---|
10 | Mat2 Mat2::operator*(const Mat2& m) const
|
---|
11 | {
|
---|
12 | Mat2 A;
|
---|
13 | int i,j;
|
---|
14 |
|
---|
15 | for(i=0;i<2;i++)
|
---|
16 | for(j=0;j<2;j++)
|
---|
17 | A(i,j) = row[i]*m.col(j);
|
---|
18 |
|
---|
19 | return A;
|
---|
20 | }
|
---|
21 |
|
---|
22 | real Mat2::det()
|
---|
23 | {
|
---|
24 | return (row[0][0]*row[1][1] - row[0][1]*row[1][0]);
|
---|
25 | }
|
---|
26 |
|
---|
27 | Mat2 Mat2::transpose()
|
---|
28 | {
|
---|
29 | return Mat2(col(0), col(1));
|
---|
30 | }
|
---|
31 |
|
---|
32 | real Mat2::inverse(Mat2& inv)
|
---|
33 | {
|
---|
34 | real d = det();
|
---|
35 |
|
---|
36 | if( d==0.0 )
|
---|
37 | return 0.0;
|
---|
38 |
|
---|
39 | inv.row[0][0] = row[1][1]/d;
|
---|
40 | inv.row[0][1] = -row[1][0]/d;
|
---|
41 | inv.row[1][0] = -row[0][1]/d;
|
---|
42 | inv.row[1][1] = row[0][0]/d;
|
---|
43 |
|
---|
44 | return d;
|
---|
45 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.