OSDN Git Service

[Backup]NyARToolkit for Java
[nyartoolkit-and/nyartoolkit-and.git] / src / jp / nyatla / nyartoolkit / core / types / matrix / NyARDoubleMatrix33.java
1 /* \r
2  * PROJECT: NyARToolkit(Extension)\r
3  * --------------------------------------------------------------------------------\r
4  * The NyARToolkit is Java version ARToolkit class library.\r
5  * Copyright (C)2008 R.Iizuka\r
6  *\r
7  * This program is free software; you can redistribute it and/or\r
8  * modify it under the terms of the GNU General Public License\r
9  * as published by the Free Software Foundation; either version 2\r
10  * of the License, or (at your option) any later version.\r
11  * \r
12  * This program is distributed in the hope that it will be useful,\r
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15  * GNU General Public License for more details.\r
16  * \r
17  * You should have received a copy of the GNU General Public License\r
18  * along with this framework; if not, write to the Free Software\r
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
20  * \r
21  * For further information please contact.\r
22  *      http://nyatla.jp/nyatoolkit/\r
23  *      <airmail(at)ebony.plala.or.jp>\r
24  * \r
25  */\r
26 package jp.nyatla.nyartoolkit.core.types.matrix;\r
27 \r
28 import jp.nyatla.nyartoolkit.*;\r
29 \r
30 public class NyARDoubleMatrix33 implements INyARDoubleMatrix\r
31 {\r
32         public double m00;\r
33         public double m01;\r
34         public double m02;\r
35         public double m10;\r
36         public double m11;\r
37         public double m12;\r
38         public double m20;\r
39         public double m21;\r
40         public double m22;\r
41         public static NyARDoubleMatrix33[] createArray(int i_number)\r
42         {\r
43                 NyARDoubleMatrix33[] ret=new NyARDoubleMatrix33[i_number];\r
44                 for(int i=0;i<i_number;i++)\r
45                 {\r
46                         ret[i]=new NyARDoubleMatrix33();\r
47                 }\r
48                 return ret;\r
49         }\r
50         /**\r
51          * 遅いからあんまり使わないでね。\r
52          */\r
53         public void setValue(double[] i_value)\r
54         {\r
55                 this.m00=i_value[0];\r
56                 this.m01=i_value[1];\r
57                 this.m02=i_value[2];\r
58                 this.m10=i_value[3];\r
59                 this.m11=i_value[4];\r
60                 this.m12=i_value[5];\r
61                 this.m20=i_value[6];\r
62                 this.m21=i_value[7];\r
63                 this.m22=i_value[8];\r
64                 return;\r
65         }\r
66         /**\r
67          * 遅いからあんまり使わないでね。\r
68          */\r
69         public void getValue(double[] o_value)\r
70         {\r
71                 o_value[0]=this.m00;\r
72                 o_value[1]=this.m01;\r
73                 o_value[2]=this.m02;\r
74                 o_value[3]=this.m10;\r
75                 o_value[4]=this.m11;\r
76                 o_value[5]=this.m12;\r
77                 o_value[6]=this.m20;\r
78                 o_value[7]=this.m21;\r
79                 o_value[8]=this.m22;\r
80                 return;\r
81         }\r
82         public boolean inverse(NyARDoubleMatrix33 i_src)\r
83         {\r
84                 final double a11,a12,a13,a21,a22,a23,a31,a32,a33;\r
85                 final double b11,b12,b13,b21,b22,b23,b31,b32,b33;       \r
86                 a11=i_src.m00;a12=i_src.m01;a13=i_src.m02;\r
87                 a21=i_src.m10;a22=i_src.m11;a23=i_src.m12;\r
88                 a31=i_src.m20;a32=i_src.m21;a33=i_src.m22;\r
89                 \r
90                 b11=a22*a33-a23*a32;\r
91                 b12=a32*a13-a33*a12;\r
92                 b13=a12*a23-a13*a22;\r
93                 \r
94                 b21=a13*a31-a21*a33;\r
95                 b22=a33*a11-a31*a13;\r
96                 b23=a13*a21-a11*a23;\r
97                 \r
98                 b31=a21*a32-a22*a31;\r
99                 b32=a31*a12-a32*a11;\r
100                 b33=a11*a22-a12*a21;\r
101                                 \r
102                 double det_1=a11*b11+a21*b12+a31*b13;\r
103                 if(det_1==0){\r
104                         return false;\r
105                 }\r
106                 det_1=1/det_1;\r
107 \r
108                 this.m00=b11*det_1;\r
109                 this.m01=b12*det_1;\r
110                 this.m02=b13*det_1;\r
111                 \r
112                 this.m10=b21*det_1;\r
113                 this.m11=b22*det_1;\r
114                 this.m12=b23*det_1;\r
115                 \r
116                 this.m20=b31*det_1;\r
117                 this.m21=b32*det_1;\r
118                 this.m22=b33*det_1;\r
119                 \r
120                 return true;\r
121         }               \r
122         \r
123 }\r