You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2011/11/10 22:02:55 UTC
svn commit: r1200545 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/geometry/euclidean/threed/Rotation.java
site/xdoc/changes.xml
test/java/org/apache/commons/math/geometry/euclidean/threed/RotationTest.java
Author: luc
Date: Thu Nov 10 21:02:54 2011
New Revision: 1200545
URL: http://svn.apache.org/viewvc?rev=1200545&view=rev
Log:
Added applyTo and applyInverseTo methods in the Rotation class that
handle directly arrays instead of Vector3D instances.
Patch provided by Jan Kotek.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Rotation.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/RotationTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Rotation.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Rotation.java?rev=1200545&r1=1200544&r2=1200545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Rotation.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/geometry/euclidean/threed/Rotation.java Thu Nov 10 21:02:54 2011
@@ -847,6 +847,25 @@ public class Rotation implements Seriali
}
+ /** Apply the rotation to a vector stored in an array.
+ * @param in an array with three items which stores vector to rotate
+ * @param out an array with three items to put result to (it can be the same
+ * array as in)
+ */
+ public void applyTo(final double[] in, final double[] out) {
+
+ final double x = in[0];
+ final double y = in[1];
+ final double z = in[2];
+
+ final double s = q1 * x + q2 * y + q3 * z;
+
+ out[0] = 2 * (q0 * (x * q0 - (q2 * z - q3 * y)) + s * q1) - x;
+ out[1] = 2 * (q0 * (y * q0 - (q3 * x - q1 * z)) + s * q2) - y;
+ out[2] = 2 * (q0 * (z * q0 - (q1 * y - q2 * x)) + s * q3) - z;
+
+ }
+
/** Apply the inverse of the rotation to a vector.
* @param u vector to apply the inverse of the rotation to
* @return a new vector which such that u is its image by the rotation
@@ -866,6 +885,26 @@ public class Rotation implements Seriali
}
+ /** Apply the inverse of the rotation to a vector stored in an array.
+ * @param in an array with three items which stores vector to rotate
+ * @param out an array with three items to put result to (it can be the same
+ * array as in)
+ */
+ public void applyInverseTo(final double[] in, final double[] out) {
+
+ final double x = in[0];
+ final double y = in[1];
+ final double z = in[2];
+
+ final double s = q1 * x + q2 * y + q3 * z;
+ final double m0 = -q0;
+
+ out[0] = 2 * (m0 * (x * m0 - (q2 * z - q3 * y)) + s * q1) - x;
+ out[1] = 2 * (m0 * (y * m0 - (q3 * x - q1 * z)) + s * q2) - y;
+ out[2] = 2 * (m0 * (z * m0 - (q1 * y - q2 * x)) + s * q3) - z;
+
+ }
+
/** Apply the instance to another rotation.
* Applying the instance to a rotation is computing the composition
* in an order compliant with the following rule : let u be any
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1200545&r1=1200544&r2=1200545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Nov 10 21:02:54 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="3.0" date="TBD" description="TBD">
+ <action dev="luc" type="add" due-to="Jan Kotek" >
+ Added applyTo and applyInverseTo methods in the Rotation class that
+ handle directly arrays instead of Vector3D instances.
+ </action>
<action dev="luc" type="fix" issue="MATH-196" >
Added adapters for simple bound constraints optimization that can be
used for all direct optimization methods, including the ones that do not
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/RotationTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/RotationTest.java?rev=1200545&r1=1200544&r2=1200545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/RotationTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/geometry/euclidean/threed/RotationTest.java Thu Nov 10 21:02:54 2011
@@ -439,6 +439,31 @@ public class RotationTest {
}
@Test
+ public void testArray() {
+
+ Rotation r = new Rotation(new Vector3D(2, -3, 5), 1.7);
+
+ for (double x = -0.9; x < 0.9; x += 0.2) {
+ for (double y = -0.9; y < 0.9; y += 0.2) {
+ for (double z = -0.9; z < 0.9; z += 0.2) {
+ Vector3D u = new Vector3D(x, y, z);
+ Vector3D v = r.applyTo(u);
+ double[] inOut = new double[] { x, y, z };
+ r.applyTo(inOut, inOut);
+ Assert.assertEquals(v.getX(), inOut[0], 1.0e-10);
+ Assert.assertEquals(v.getY(), inOut[1], 1.0e-10);
+ Assert.assertEquals(v.getZ(), inOut[2], 1.0e-10);
+ r.applyInverseTo(inOut, inOut);
+ Assert.assertEquals(u.getX(), inOut[0], 1.0e-10);
+ Assert.assertEquals(u.getY(), inOut[1], 1.0e-10);
+ Assert.assertEquals(u.getZ(), inOut[2], 1.0e-10);
+ }
+ }
+ }
+
+ }
+
+ @Test
public void testApplyInverseTo() {
Rotation r = new Rotation(new Vector3D(2, -3, 5), 1.7);