Skip to content

Commit 1bb996e

Browse files
authored
Merge pull request #14 from WorldWindEarth/determinantFix
Determinant fix
2 parents 53a3484 + 9a59840 commit 1bb996e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/gov/nasa/worldwind/geom/Matrix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ public final double getDeterminant()
20612061
+ this.m24 * (this.m31 * this.m42 - this.m41 * this.m32));
20622062
// Columns 1, 2, 3.
20632063
result -= this.m14 *
2064-
(this.m21 * (this.m32 * this.m43 - this.m42 - this.m33)
2064+
(this.m21 * (this.m32 * this.m43 - this.m42 * this.m33)
20652065
- this.m22 * (this.m31 * this.m43 - this.m41 * this.m33)
20662066
+ this.m23 * (this.m31 * this.m42 - this.m41 * this.m32));
20672067
return result;

test/gov/nasa/worldwind/geom/MatrixTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,26 @@ public void testInverseOfNearSingular()
136136
Matrix identity = m.multiply(mInv);
137137
assertTrue("Matrix inverse is incorrect", equals(identity, Matrix.IDENTITY, NEAR_SINGULAR_EQUALITY_TOLERANCE));
138138
}
139+
140+
@Test
141+
public void testDeterminantEqualToDeterminantOfTranspose()
142+
{
143+
// Create random matrix.
144+
Matrix matrix = new Matrix(
145+
random.nextDouble(), random.nextDouble(), random.nextDouble(), random.nextDouble(),
146+
random.nextDouble(), random.nextDouble(), random.nextDouble(), random.nextDouble(),
147+
random.nextDouble(), random.nextDouble(), random.nextDouble(), random.nextDouble(),
148+
random.nextDouble(), random.nextDouble(), random.nextDouble(), random.nextDouble());
149+
150+
// Calculate the determinant.
151+
double determinant = matrix.getDeterminant();
152+
153+
// Transpose the matrix.
154+
Matrix transpose = matrix.getTranspose();
155+
156+
// The determinant and the determinant of the transpose should be equal.
157+
assertEquals(determinant, transpose.getDeterminant(), EQUALITY_TOLERANCE);
158+
}
139159

140160
//**************************************************************//
141161
//******************** Helper Methods ************************//

0 commit comments

Comments
 (0)