Skip to content

Commit 931b166

Browse files
committed
Matrix3/4: Refactor getInverse().
1 parent e3d60b1 commit 931b166

File tree

8 files changed

+25
-66
lines changed

8 files changed

+25
-66
lines changed

docs/api/en/math/Matrix3.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
106106
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
107107
</p>
108108

109-
<h3>[method:this getInverse]( [param:Matrix3 m], [param:Boolean throwOnDegenerate] )</h3>
109+
<h3>[method:this getInverse]( [param:Matrix3 m] )</h3>
110110
<p>
111-
[page:Matrix3 m] - the matrix to take the inverse of.<br />
112-
[page:Boolean throwOnDegenerate] - (optional) If true, throw an error if the matrix is degenerate (not invertible).<br /><br />
111+
[page:Matrix3 m] - the matrix to take the inverse of.<br /><br />
113112

114113
Set this matrix to the [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse] of the passed matrix [page:Matrix3 m],
115114
using the [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method].
116115

117-
If [page:Boolean throwOnDegenerate] is not set and the matrix is not invertible, set this to the 3x3 identity matrix.
116+
You can not invert a matrix with a determinant of zero. If you attempt this, the method returns a zero matrix instead.
118117
</p>
119118

120119
<h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>

docs/api/en/math/Matrix4.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,14 @@ <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
190190
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
191191
</p>
192192

193-
<h3>[method:this getInverse]( [param:Matrix4 m], [param:Boolean throwOnDegenerate] )</h3>
193+
<h3>[method:this getInverse]( [param:Matrix4 m] )</h3>
194194
<p>
195-
[page:Matrix4 m] - the matrix to take the inverse of.<br />
196-
[page:Boolean throwOnDegenerate] - (optional) If true, throw an error if the matrix is degenerate (not invertible).<br /><br />
195+
[page:Matrix4 m] - the matrix to take the inverse of.<br /><br />
197196

198197
Set this matrix to the [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse] of the passed matrix [page:Matrix4 m],
199198
using the method outlined [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm here].
200199

201-
If [page:Boolean throwOnDegenerate] is not set and the matrix is not invertible, set this to the 4x4 identity matrix.
200+
You can not invert a matrix with a determinant of zero. If you attempt this, the method returns a zero matrix instead.
202201
</p>
203202

204203

docs/api/zh/math/Matrix3.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
101101
使用基于列优先格式[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]的数组来设置该矩阵。
102102
</p>
103103

104-
<h3>[method:this getInverse]( [param:Matrix3 m], [param:Boolean throwOnDegenerate] )</h3>
104+
<h3>[method:this getInverse]( [param:Matrix3 m] )</h3>
105105
<p>
106-
[page:Matrix3 m] - 取逆的矩阵。<br />
107-
[page:Boolean throwOnDegenerate] - (optional) 如果设置为true,如果矩阵是退化的(如果不可逆的话),则会抛出一个错误。<br /><br />
106+
[page:Matrix3 m] - 取逆的矩阵。<br /><br />
108107

109-
使用逆矩阵计算方法[link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method],
110-
将当前矩阵设置为给定矩阵的逆矩阵[link:https://en.wikipedia.org/wiki/Invertible_matrix inverse],如果[page:Boolean throwOnDegenerate]
111-
参数没有设置且给定矩阵不可逆,那么将当前矩阵设置为3X3单位矩阵。
108+
Set this matrix to the [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse] of the passed matrix [page:Matrix3 m],
109+
using the [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method].
110+
111+
You can not invert a matrix with a determinant of zero. If you attempt this, the method returns a zero matrix instead.
112112
</p>
113113

114114
<h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>

docs/api/zh/math/Matrix4.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,15 @@ <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
175175
使用基于列优先格式[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]的数组来设置该矩阵。
176176
</p>
177177

178-
<h3>[method:this getInverse]( [param:Matrix4 m], [param:Boolean throwOnDegenerate] )</h3>
178+
<h3>[method:this getInverse]( [param:Matrix4 m] )</h3>
179179
<p>
180-
[page:Matrix3 m] - 取逆的矩阵。<br />
181-
[page:Boolean throwOnDegenerate] - (optional) 如果设置为true,如果矩阵是退化的(如果不可逆的话),则会抛出一个错误。<br /><br />
180+
[page:Matrix3 m] - 取逆的矩阵。<br /><br />
182181

183-
使用逆矩阵计算方法[link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method],
184-
将当前矩阵设置为给定矩阵的逆矩阵[link:https://en.wikipedia.org/wiki/Invertible_matrix inverse],如果[page:Boolean throwOnDegenerate]
185-
参数没有设置且给定矩阵不可逆,那么将当前矩阵设置为3X3单位矩阵。
186-
</p>
182+
Set this matrix to the [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse] of the passed matrix [page:Matrix4 m],
183+
using the method outlined [link:http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm here].
187184

185+
You can not invert a matrix with a determinant of zero. If you attempt this, the method returns a zero matrix instead.
186+
</p>
188187

189188
<h3>[method:Float getMaxScaleOnAxis]()</h3>
190189
<p>获取3个轴方向的最大缩放值。</p>

src/math/Matrix3.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export interface Matrix {
2828
determinant(): number;
2929

3030
/**
31-
* getInverse(matrix:T, throwOnInvertible?:boolean):T;
31+
* getInverse(matrix:T):T;
3232
*/
33-
getInverse( matrix: Matrix, throwOnInvertible?: boolean ): Matrix;
33+
getInverse( matrix: Matrix ): Matrix;
3434

3535
/**
3636
* transpose():T;

src/math/Matrix3.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,7 @@ Object.assign( Matrix3.prototype, {
164164

165165
},
166166

167-
getInverse: function ( matrix, throwOnDegenerate ) {
168-
169-
if ( matrix && matrix.isMatrix4 ) {
170-
171-
console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
172-
173-
}
167+
getInverse: function ( matrix ) {
174168

175169
var me = matrix.elements,
176170
te = this.elements,
@@ -185,23 +179,7 @@ Object.assign( Matrix3.prototype, {
185179

186180
det = n11 * t11 + n21 * t12 + n31 * t13;
187181

188-
if ( det === 0 ) {
189-
190-
var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
191-
192-
if ( throwOnDegenerate === true ) {
193-
194-
throw new Error( msg );
195-
196-
} else {
197-
198-
console.warn( msg );
199-
200-
}
201-
202-
return this.identity();
203-
204-
}
182+
if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
205183

206184
var detInv = 1 / det;
207185

src/math/Matrix4.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class Matrix4 implements Matrix {
117117
* Sets this matrix to the inverse of matrix m.
118118
* Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm.
119119
*/
120-
getInverse( m: Matrix4, throwOnDegeneratee?: boolean ): Matrix4;
120+
getInverse( m: Matrix4 ): Matrix4;
121121

122122
/**
123123
* Multiplies the columns of this matrix by vector v.

src/math/Matrix4.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Object.assign( Matrix4.prototype, {
504504

505505
},
506506

507-
getInverse: function ( m, throwOnDegenerate ) {
507+
getInverse: function ( m ) {
508508

509509
// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
510510
var te = this.elements,
@@ -522,23 +522,7 @@ Object.assign( Matrix4.prototype, {
522522

523523
var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
524524

525-
if ( det === 0 ) {
526-
527-
var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
528-
529-
if ( throwOnDegenerate === true ) {
530-
531-
throw new Error( msg );
532-
533-
} else {
534-
535-
console.warn( msg );
536-
537-
}
538-
539-
return this.identity();
540-
541-
}
525+
if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
542526

543527
var detInv = 1 / det;
544528

0 commit comments

Comments
 (0)