From: Gary P. <gpa...@gm...> - 2009-08-13 06:46:17
|
The current implementation of the rotation and the determinant. These implementations are restricted to 2-dimensions at the moment. Plans to extend this to n-dimensions is planned. Signed-off-by: Gary Pampara <gpa...@gm...> --- pom.xml | 5 ---- .../cilib/type/types/container/Matrix.java | 23 ++++++++++++++++++++ .../cilib/type/types/container/MatrixTest.java | 19 ++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index bf3b9f4..fcc9dff 100644 --- a/pom.xml +++ b/pom.xml @@ -163,11 +163,6 @@ </configuration> </plugin> <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.4.2</version> - </plugin> - <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>javacc-maven-plugin</artifactId> <version>2.5</version> diff --git a/src/main/java/net/sourceforge/cilib/type/types/container/Matrix.java b/src/main/java/net/sourceforge/cilib/type/types/container/Matrix.java index f42abb6..913ff7f 100644 --- a/src/main/java/net/sourceforge/cilib/type/types/container/Matrix.java +++ b/src/main/java/net/sourceforge/cilib/type/types/container/Matrix.java @@ -169,6 +169,29 @@ public final class Matrix implements Type { } /** + * + * @param angle The rotation angle defined in radians. + * @return + */ + public Matrix rotate(double angle) { + Matrix rotation = new Matrix(2, 2); + rotation.contents[0][0] = Math.cos(angle); + rotation.contents[0][1] = -Math.sin(angle); + rotation.contents[1][0] = Math.sin(angle); + rotation.contents[1][1] = Math.cos(angle); + + return this.times(rotation); + } + + /** + * + * @return + */ + public double determinant() { + return contents[0][0]*contents[1][1] - contents[1][0]*contents[0][1]; + } + + /** * {@inheritDoc} */ @Override diff --git a/src/test/java/net/sourceforge/cilib/type/types/container/MatrixTest.java b/src/test/java/net/sourceforge/cilib/type/types/container/MatrixTest.java index 6144707..0c2c98e 100644 --- a/src/test/java/net/sourceforge/cilib/type/types/container/MatrixTest.java +++ b/src/test/java/net/sourceforge/cilib/type/types/container/MatrixTest.java @@ -211,6 +211,25 @@ public class MatrixTest { } } + @Test + public void rotation() { + double angle = Math.PI / 4.0; + + Matrix matrix = Matrix.builder().rows(2).columns(2).addRow(1.0, 1.0).addRow(1.0, 1.0).build(); + Matrix result = matrix.rotate(angle); + + Assert.assertThat(result.valueAt(0, 0), is(1.414213562373095)); + Assert.assertThat(result.valueAt(0, 1), is(1.1102230246251565E-16)); + Assert.assertThat(result.valueAt(1, 0), is(1.414213562373095)); + Assert.assertThat(result.valueAt(1, 1), is(1.1102230246251565E-16)); + } + + @Test + public void determinant() { + Matrix matrix = Matrix.builder().rows(2).columns(2).addRow(1.0, 1.0).addRow(1.0, 1.0).build(); + Assert.assertThat(matrix.determinant(), is(0.0)); + } + @Test(expected=IllegalStateException.class) public void invalidIdentity() { Matrix.builder().rows(2).columns(5).identity().build(); -- 1.6.4 |