1: package com.jme.math;
2:
3: import java.io.IOException;
4: import java.io.Serializable;
5: import java.nio.FloatBuffer;
6: import java.util.logging.Logger;
7:
8: import com.jme.system.JmeException;
9: import com.jme.util.export.InputCapsule;
10: import com.jme.util.export.JMEExporter;
11: import com.jme.util.export.JMEImporter;
12: import com.jme.util.export.OutputCapsule;
13: import com.jme.util.export.Savable;
14: import com.jme.util.geom.BufferUtils;
15:
16: /**
17: * <code>Matrix3f</code> defines a 3x3 matrix. Matrix data is maintained
18: * internally and is accessible via the get and set methods. Convenience methods
19: * are used for matrix operations as well as generating a matrix from a given
20: * set of values.<br/>
21: * 3X3矩阵类
22: *
23: * @author Mark Powell
24: * @author Joshua Slack
25: */
26: public class Matrix3f implements Serializable, Savable, Cloneable {
27: private static final Logger logger = Logger.getLogger(Matrix3f.class
28: .getName());
29:
30: private static final long serialVersionUID = 1L;
31:
32: public float m00, m01, m02;
33: public float m10, m11, m12;
34: public float m20, m21, m22;
35:
36: /**
37: * Constructor instantiates a new <code>Matrix3f</code> object. The initial
38: * values for the matrix is that of the identity matrix.<br/>
39: * 默认构造单位矩阵
40: *
41: */
42: public Matrix3f() {
43: loadIdentity();
44: }
45:
46: /**
47: * constructs a matrix with the given values.
48: *
49: * @param m00
50: * 0x0 in the matrix.
51: * @param m01
52: * 0x1 in the matrix.
53: * @param m02
54: * 0x2 in the matrix.
55: * @param m10
56: * 1x0 in the matrix.
57: * @param m11
58: * 1x1 in the matrix.
59: * @param m12
60: * 1x2 in the matrix.
61: * @param m20
62: * 2x0 in the matrix.
63: * @param m21
64: * 2x1 in the matrix.
65: * @param m22
66: * 2x2 in the matrix.
67: */
68: public Matrix3f(float m00, float m01, float m02, float m10, float m11,
69: float m12, float m20, float m21, float m22) {
70:
71: this.m00 = m00;
72: this.m01 = m01;
73: this.m02 = m02;
74: this.m10 = m10;
75: this.m11 = m11;
76: this.m12 = m12;
77: this.m20 = m20;
78: this.m21 = m21;
79: this.m22 = m22;
80: }
81:
82: /**
83: * Copy constructor that creates a new <code>Matrix3f</code> object that is
84: * the same as the provided matrix.
85: *
86: * @param mat
87: * the matrix to copy.
88: */
89: public Matrix3f(Matrix3f mat) {
90: copy(mat);
91: }
92:
93: /**
94: * <code>copy</code> transfers the contents of a given matrix to this
95: * matrix. If a null matrix is supplied, this matrix is set to the identity
96: * matrix.
97: *
98: * @param matrix
99: * the matrix to copy.
100: */
101: public void copy(Matrix3f matrix) {
102: if (null == matrix) {
103: loadIdentity();
104: } else {
105: m00 = matrix.m00;
106: m01 = matrix.m01;
107: m02 = matrix.m02;
108: m10 = matrix.m10;
109: m11 = matrix.m11;
110: m12 = matrix.m12;
111: m20 = matrix.m20;
112: m21 = matrix.m21;
113: m22 = matrix.m22;
114: }
115: }
116:
117: /**
118: * <code>get</code> retrieves a value from the matrix at the given position.
119: * If the position is invalid a <code>JmeException</code> is thrown.<br/>
120: * 获取指定位置的元素值
121: *
122: * @param i
123: * the row index.行索引(取值范围:0、1、2)
124: * @param j
125: * the colum index.列索引(取值范围:0、1、2)
126: * @return the value at (i, j).
127: */
128: public float get(int i, int j) {
129: switch (i) {
130: case 0:
131: switch (j) {
132: case 0:
133: return m00;
134: case 1:
135: return m01;
136: case 2:
137: return m02;
138: }
139: case 1:
140: switch (j) {
141: case 0:
142: return m10;
143: case 1:
144: return m11;
145: case 2:
146: return m12;
147: }
148: case 2:
149: switch (j) {
150: case 0:
151: return m20;
152: case 1:
153: return m21;
154: case 2:
155: return m22;
156: }
157: }
158:
159: logger.warning("Invalid matrix index.");
160: throw new JmeException("Invalid indices into matrix.");
161: }
162:
163: /**
164: * <code>get(float[])</code> returns the matrix in row-major or column-major
165: * order.<br/>
166: * 将矩阵按行或列的顺序存入参数data数组中
167: *
168: * @param data
169: * The array to return the data into. This array can be 9 or 16
170: * floats in size. Only the upper 3x3 are assigned to in the case
171: * of a 16 element array.
172: * @param rowMajor
173: * True for row major storage in the array (translation in
174: * elements 3, 7, 11 for a 4x4), false for column major
175: * (translation in elements 12, 13, 14 for a 4x4).
176: */
177: public void get(float[] data, boolean rowMajor) {
178: if (data.length == 9) {
179: if (rowMajor) {
180: data[0] = m00;
181: data[1] = m01;
182: data[2] = m02;
183: data[3] = m10;
184: data[4] = m11;
185: data[5] = m12;
186: data[6] = m20;
187: data[7] = m21;
188: data[8] = m22;
189: } else {
190: data[0] = m00;
191: data[1] = m10;
192: data[2] = m20;
193: data[3] = m01;
194: data[4] = m11;
195: data[5] = m21;
196: data[6] = m02;
197: data[7] = m12;
198: data[8] = m22;
199: }
200: } else if (data.length == 16) {
201: if (rowMajor) {
202: data[0] = m00;
203: data[1] = m01;
204: data[2] = m02;
205: data[4] = m10;
206: data[5] = m11;
207: data[6] = m12;
208: data[8] = m20;
209: data[9] = m21;
210: data[10] = m22;
211: } else {
212: data[0] = m00;
213: data[1] = m10;
214: data[2] = m20;
215: data[4] = m01;
216: data[5] = m11;
217: data[6] = m21;
218: data[8] = m02;
219: data[9] = m12;
220: data[10] = m22;
221: }
222: } else {
223: throw new JmeException(
224: "Array size must be 9 or 16 in Matrix3f.get().");
225: }
226: }
227:
228: /**
229: * <code>getColumn</code> returns one of three columns specified by the
230: * parameter. This column is returned as a <code>Vector3f</code> object.<br/>
231: * 获取指定列构造的向量
232: *
233: * @param i
234: * the column to retrieve. Must be between 0 and 2.
235: * @return the column specified by the index.
236: */
237: public Vector3f getColumn(int i) {
238: return getColumn(i, null);
239: }
240:
241: /**
242: * <code>getColumn</code> returns one of three columns specified by the
243: * parameter. This column is returned as a <code>Vector3f</code> object.<br/>
244: * 获取指定列构造的向量
245: *
246: * @param i
247: * the column to retrieve. Must be between 0 and 2.
248: * @param store
249: * the vector object to store the result in. if null, a new one
250: * is created.
251: * @return the column specified by the index.
252: */
253: public Vector3f getColumn(int i, Vector3f store) {
254: if (store == null)
255: store = new Vector3f();
256: switch (i) {
257:
分享到:
相关推荐
51单片机3x3矩阵键盘驱动程序,经过巧妙的算法处理,该驱动程序只占用6个IO口,其他两个IO口可以正常使用,不会受到矩阵键盘的影响,能够节省宝贵的IO口资源,特地分享给需要的朋友,拿走不谢~~
计算3X3矩阵模 C语言程序,含代码,直接计算
定义了一个矩阵的储存方法CMatrix 定义了一个矩阵的预算方法CMatrix_Operation 代码可以实现以下功能: ...7.矩阵的逆(只限于3x3) 8.向量的单位化 此代码为本人做3D建模(空间旋转)时用的基础代码
matlab开发-2x2和3x3矩阵的多个等效值。用卡尔丹公式一次计算多重(3×3)矩阵的特征值
COMP_DECOMP_MATRIX:从欧拉角(以度为单位)组成 3x3 旋转矩阵或将 3x3 旋转矩阵分解为欧拉角(以度为单位) 输入:1x3 欧拉向量围绕 x 旋转 (1), y 旋转 (2) 和 z、旋转 (3) 或 3x3 旋转矩阵输出:表示绕 x、y 和 ...
3x3矩阵键盘显示通过按键用一位数码管显示012345678
矩阵的Java实现,含矩阵的所有运算,也可与向量进行运算表示图形的变换。
C语言 实现3X3矩阵主对角线和副对角线求和,输入矩阵,输出主对角线和副对角线,欢迎下载,桌面系统VS环境直接运行
3X3键盘 有PCB和原理图 我的原理图布局是一排的,慎下。不过你也可以中信布局。
汇编语言实现矩阵乘法
源代码_3x3中值滤波器的fpga实现_VERILOG [ 本帖最后由 david0915 于 2007-8-13 10:58 编辑 ] 滤波器 , 源代码
在使用循环语句实现矩阵元素的行列对调,注意在循环语句中究竟需要对哪些元素进行操作。
简易的矩阵加密编码法(cipher),使用2*2、3*3矩阵加密编码。 M 是用来将字串 "编码" 的矩阵 ,可以任意指定矩阵中的元素,但是必须是一个n×n的可逆方阵(invertible square matrix),这里只简单的以2×2的方阵来表示...
阿杜伊诺3x3x3 LED矩阵 由Joshua Manley创建
计算许多3x3实对称矩阵的特征值。 计算是非迭代的,基于完全矢量化的 matlab 矩阵运算,并且支持 GPU 计算。 它可以快速有效地同时处理多个 3×3 矩阵。 此代码特别适合 3D 中的张量/黎曼微积分、体积张量图像的可视...
得一个 3×3 的矩阵转置,用一函数实现之。在主函数中用 scanf 函数输入矩阵元素
从键盘输入一个3*3的矩阵,要求:输出此矩阵对应的转置矩阵(所谓转置,指的是对任意元素Pi,j和对应的Pj,i交换)。
请注意,此函数不返回 EIGEN VECTORS。 当必须为大量矩阵计算特征值时,此函数比循环 EIG 更快。 测试表明它可以加速10倍
本实验为设计性实验,注重培养学生的动手能力,通过实验使学生掌握数组的定义和使用方法 ,学习基本排序和查找算法,能够使用数组编写比较复杂的程序。
学生可以看到如何计算 3x3 矩阵的行列式。